This document discusses using RSpec and behavior driven development (BDD) to write specifications and tests for software. It covers writing user stories with a Given-When-Then structure to define scenarios and test the full software stack. Examples are given of using RSpec matchers and Webrat to specify and test user interface elements and behavior. The process of writing a story, implementing the code, and running tests is also outlined.
Software projects are rarely on-spec, on-time and on-budget, and the primary cause is miscommunication. As Martin Fowler says, there is a "yawning crevasse of doom" between stakeholders and developers, full of misunderstanding. How do you make sure that you're building something that adds value? How do you know you're building the thing that was asked for? How does your bottom line affect user experience?
Into the fray leaps Cucumber, a business-readable DSL combined with an awesome Ruby library that lets domain experts express business requirements as executable user stories. We'll cover outside-in, story-driven development with Cucumber, how to write effective stories, and how to make Cucumber work for your project.
(as given to CharlotteRuby on Jan 6, 2010)
Outside-in Development with Cucumber and RspecJoseph Wilk
Talk given by Joseph Wilk at Scotland on Rails 2009. Examines how Cucumber and Rspec fit together in the testing workflow, how and why Cucumber is useful and how it works. Walks through a simple example based on renting DVDs showing how to use Cucumber and some of the best practices. Looks at how Webrat can drive Selenium to in-turn drive Cucumber features through the browser.
Behavior Driven Development - How To Start with Behatimoneytech
This document discusses Behaviour Driven Development (BDD) and how it can be used to write automated tests for software features using a Given-When-Then structure. BDD involves writing human-readable scenarios that describe how a feature should behave. These scenarios are then automated as tests using a framework like Cucumber that supports the Gherkin language. The document provides examples of steps written in Gherkin including Given, When, and Then steps to set up tests, trigger actions, and assert outcomes. It also gives examples of scenarios that could be tested, such as checking credit cards are filtered properly based on user selections.
This document discusses Cucumber, a tool for behavior-driven development and end-to-end testing of web applications. It provides examples of writing Cucumber features and scenarios in plain English or other human-readable languages. Scenarios define steps that map to code using a given-when-then structure. The document demonstrates steps for user login and navigation, arithmetic calculations, and more. It also briefly discusses identifying scenarios, automating tests, and agreeing on step definitions.
The document discusses Cucumber, a tool for writing acceptance tests in a business-readable domain-specific language called Gherkin. It touches on how Cucumber supports over 28 languages by compiling Gherkin grammars into the target language. It also provides examples of tagging scenarios and features in Cucumber to enable focused testing. Finally, it recommends further reading resources for learning more about Cucumber.
“Can we integrate mobile, web and API testing into a single open-source automation framework? And, we only want all the test scripts to be written in human-readable language, we want them to be easily integrated to CI system. It’s quite a hard question, isn’t it?” If you or your organization also have the same question and still on trying to find solution for that. Then, we believe that this seminar is for you! At the seminar, we will cover the following topics:
The Need of Automation Testing Nowadays
How BDD Cuke and Ruby on Rails can help
A Universal Automation Framework: Mobile, Web, API and CI Integration
CodeIgniter is an MVC framework that helps developers write clean, well-organized PHP code. It provides features like clean URLs, form and data validation, security protections, and image manipulation tools. CodeIgniter aims to be intuitive and flexible, allowing developers to extend its libraries and only load what they need. The framework and its community are well supported through documentation and forums online.
This document discusses using RSpec and behavior driven development (BDD) to write specifications and tests for software. It covers writing user stories with a Given-When-Then structure to define scenarios and test the full software stack. Examples are given of using RSpec matchers and Webrat to specify and test user interface elements and behavior. The process of writing a story, implementing the code, and running tests is also outlined.
Software projects are rarely on-spec, on-time and on-budget, and the primary cause is miscommunication. As Martin Fowler says, there is a "yawning crevasse of doom" between stakeholders and developers, full of misunderstanding. How do you make sure that you're building something that adds value? How do you know you're building the thing that was asked for? How does your bottom line affect user experience?
Into the fray leaps Cucumber, a business-readable DSL combined with an awesome Ruby library that lets domain experts express business requirements as executable user stories. We'll cover outside-in, story-driven development with Cucumber, how to write effective stories, and how to make Cucumber work for your project.
(as given to CharlotteRuby on Jan 6, 2010)
Outside-in Development with Cucumber and RspecJoseph Wilk
Talk given by Joseph Wilk at Scotland on Rails 2009. Examines how Cucumber and Rspec fit together in the testing workflow, how and why Cucumber is useful and how it works. Walks through a simple example based on renting DVDs showing how to use Cucumber and some of the best practices. Looks at how Webrat can drive Selenium to in-turn drive Cucumber features through the browser.
Behavior Driven Development - How To Start with Behatimoneytech
This document discusses Behaviour Driven Development (BDD) and how it can be used to write automated tests for software features using a Given-When-Then structure. BDD involves writing human-readable scenarios that describe how a feature should behave. These scenarios are then automated as tests using a framework like Cucumber that supports the Gherkin language. The document provides examples of steps written in Gherkin including Given, When, and Then steps to set up tests, trigger actions, and assert outcomes. It also gives examples of scenarios that could be tested, such as checking credit cards are filtered properly based on user selections.
This document discusses Cucumber, a tool for behavior-driven development and end-to-end testing of web applications. It provides examples of writing Cucumber features and scenarios in plain English or other human-readable languages. Scenarios define steps that map to code using a given-when-then structure. The document demonstrates steps for user login and navigation, arithmetic calculations, and more. It also briefly discusses identifying scenarios, automating tests, and agreeing on step definitions.
The document discusses Cucumber, a tool for writing acceptance tests in a business-readable domain-specific language called Gherkin. It touches on how Cucumber supports over 28 languages by compiling Gherkin grammars into the target language. It also provides examples of tagging scenarios and features in Cucumber to enable focused testing. Finally, it recommends further reading resources for learning more about Cucumber.
“Can we integrate mobile, web and API testing into a single open-source automation framework? And, we only want all the test scripts to be written in human-readable language, we want them to be easily integrated to CI system. It’s quite a hard question, isn’t it?” If you or your organization also have the same question and still on trying to find solution for that. Then, we believe that this seminar is for you! At the seminar, we will cover the following topics:
The Need of Automation Testing Nowadays
How BDD Cuke and Ruby on Rails can help
A Universal Automation Framework: Mobile, Web, API and CI Integration
CodeIgniter is an MVC framework that helps developers write clean, well-organized PHP code. It provides features like clean URLs, form and data validation, security protections, and image manipulation tools. CodeIgniter aims to be intuitive and flexible, allowing developers to extend its libraries and only load what they need. The framework and its community are well supported through documentation and forums online.
greach 2014 marco vermeulen bdd using cucumber jvm and groovyJessie Evangelista
Using examples at multiple levels, Behavior Driven Development (BDD) creates a shared understanding to deliver software that matters. Cucumber allows writing executable specifications in a simple markup language called Gherkin and parsing them into tests. The Cucumber anatomy includes Gherkin features, step definitions that parse and execute the steps, and hooks to run code before and after scenarios. The Grails Cucumber plugin makes BDD easy in Grails through conventions, and was demonstrated in an example using GORM, Geb pages, and Spock specifications.
The document discusses best practices for using RSpec, a testing library for Ruby projects. It provides examples of good and bad ways to write RSpec tests and describes techniques like using contexts and shared examples to organize tests and DRY up code. The document emphasizes testing edge cases, mocking only when needed, creating data dynamically in tests rather than using fixtures, and following practices like describing methods under test and having single-expectation tests. It encourages starting to use RSpec and provides contact information for the author to learn more.
- The document discusses testing Ruby code with RSpec, including setting up RSpec, the four phases of testing (setup, exercise, verify, teardown), describe and it blocks, matchers, stubs, mocks, focus and skip, shared examples, shared contexts, and custom matchers.
- Key aspects covered include initializing RSpec with bundle, writing tests with describe/it blocks, using matchers like expect() to verify results, and techniques like stubs, mocks, focus/skip, and shared examples/contexts.
- The document provides examples of testing methods, using matchers, stubs, focus/skip, and shared examples/contexts.
This document provides an overview of various topics related to optimizing performance in Ruby on Rails web applications, including:
- Different Rails application servers like Passenger, Unicorn, and Puma.
- Factors that affect web request performance like redirects, DNS lookups, and front-end loading.
- Database performance issues like N+1 queries and missing indexes that can be addressed through eager loading and adding indexes.
- Using caching at different levels like page, action, and fragment caching as well as ensuring caches are expired properly.
- Using background job queues like Resque to process long-running tasks asynchronously.
- The importance of monitoring applications and addressing performance issues that
The document provides an overview of jQuery, a popular JavaScript library, including its history and benefits such as easy DOM manipulation, AJAX capabilities, and cross-browser compatibility. It then demonstrates several jQuery functions and selectors for modifying HTML elements, handling events, and making AJAX requests to update content without page refreshes. Examples are given for selecting elements, updating styles, handling events like clicks, and validating form input with plugins.
Testing in Rails allows developers to write automated test suites using frameworks like Minitest and RSpec. These frameworks interact with the codebase to run tests from the command line and check that code works as expected. Tests can verify functionality when code is initially written and also help prevent breaks when code is refactored. Test-driven development involves writing tests before code so that tests guide code implementation.
The document discusses RSpec, a behavior-driven development (BDD) framework for testing Ruby code. It describes how RSpec allows writing tests in a natural language style using "should" statements. Examples are provided for different types of RSpec tests, including model, controller, and view tests. Shared examples, custom matchers, and integration with Cucumber for writing tests in a storytelling format are also covered. The document concludes with information on installing and running RSpec and generating reports from test results.
CodeIgniter is an MVC framework that allows developers to build applications in a logical manner. It provides features like clean URLs, form validation, security protections, and image manipulation tools out of the box. While CodeIgniter does not enforce rigid structures, it enables organization of applications into models, views, and controllers. It aims to help developers write code faster without forcing atypical approaches. The framework has good documentation and an active community for support.
The document discusses setting up a basic online store application in Rails. It covers generating a Store controller, routing requests to the store index action, displaying a list of products from the database, adding styles with CSS, using Rails helpers like number_to_currency to format prices, and writing functional tests for the controller. Homework includes adding a date to the sidebar, experimenting with number formatting options, and writing tests for the products controller.
This document discusses Behavior-Driven Development (BDD) and automation testing using Cucumber. It provides an example of writing a Cucumber scenario to test logging into a system. It then demonstrates how to automate this scenario by writing step definitions in Ruby. The document also presents pros and cons of the BDD and Cucumber approach, and includes a demo of using Cucumber to test a web application and web services.
Excellent is a static analysis gem that finds the nasty lines in your code. It implements a comprehensive set of checks for possibly buggy parts of your app that would otherwise make it into your repo and eventually to the production server.
This document provides an overview of routing changes in Rails 3, including:
- Matching routes using "match" instead of "map.connect" and optional segments.
- Namespaces, scopes, and constraints for organizing and restricting routes.
- Default RESTful routes and generating resources.
- Redirects can now be specified as Rack apps or Procs.
- Mounting other Rack endpoints at specific paths.
This document provides an introduction and overview of Ruby on Rails, including: its history and initial release in 2004; the Model-View-Controller architecture and included components; installing and setting up a basic Rails application; scaffolding a product catalog with CRUD functionality; adding validation, testing, and pushing the application to Heroku for deployment. It then demonstrates expanding the application by adding a shopping cart and checkout functionality using additional scaffolds, models, and controllers.
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Caldera Labs
This document discusses using AngularJS to build single page applications for WordPress admin interfaces that use the WordPress REST API. It covers why this approach is beneficial, how to set it up using Angular routing, controllers, factories and HTTP requests to interact with the REST API. Benefits mentioned include making WordPress interfaces more modern and dynamic, empowering others to build plugins in a decentralized way, and the ease of transitioning to software as a service models. The document encourages readers to learn Angular and check out additional resources on the topic.
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
The document provides an overview of a workshop on using the WordPress REST API and AngularJS. The workshop will cover REST API fundamentals, building custom REST APIs, unit testing APIs, and getting started with AngularJS by building controllers, templates, services, and factories. Attendees will learn through hands-on examples and code walkthroughs applied to real world projects.
Simplifying Code: Monster to Elegant in 5 Stepstutec
The document discusses techniques for refactoring code, including intention revealing methods, null objects, and replacing large methods with method objects. Intention revealing methods transform comments into descriptive method names to improve code readability. Null objects avoid null values and unnecessary conditionals. Large methods can be refactored by extracting the logic into a new class. The goal of refactoring is to improve code quality, shared understanding, and prevent bugs and performance issues.
This document discusses using RSpec for testing Rails applications. It covers installing RSpec and RSpec-rails, generating Rails projects with different frameworks and databases, generating scaffolds for models, running tests, and using RSpec matchers, stubs, mocks and other features for testing controllers, models, views and test coverage. It also introduces the autotest tool for automatically running tests on file changes.
RSpec is a testing framework for Ruby that supports behavior-driven development (BDD). It allows writing tests in a descriptive manner using plain English "examples" and "expectations". RSpec tests isolate the unit being tested using mocks and stubs. This allows writing true unit tests that focus on interactions between objects. RSpec provides tools like should and matchers for writing expectations as well as a mocking framework for stubbing method calls.
greach 2014 marco vermeulen bdd using cucumber jvm and groovyJessie Evangelista
Using examples at multiple levels, Behavior Driven Development (BDD) creates a shared understanding to deliver software that matters. Cucumber allows writing executable specifications in a simple markup language called Gherkin and parsing them into tests. The Cucumber anatomy includes Gherkin features, step definitions that parse and execute the steps, and hooks to run code before and after scenarios. The Grails Cucumber plugin makes BDD easy in Grails through conventions, and was demonstrated in an example using GORM, Geb pages, and Spock specifications.
The document discusses best practices for using RSpec, a testing library for Ruby projects. It provides examples of good and bad ways to write RSpec tests and describes techniques like using contexts and shared examples to organize tests and DRY up code. The document emphasizes testing edge cases, mocking only when needed, creating data dynamically in tests rather than using fixtures, and following practices like describing methods under test and having single-expectation tests. It encourages starting to use RSpec and provides contact information for the author to learn more.
- The document discusses testing Ruby code with RSpec, including setting up RSpec, the four phases of testing (setup, exercise, verify, teardown), describe and it blocks, matchers, stubs, mocks, focus and skip, shared examples, shared contexts, and custom matchers.
- Key aspects covered include initializing RSpec with bundle, writing tests with describe/it blocks, using matchers like expect() to verify results, and techniques like stubs, mocks, focus/skip, and shared examples/contexts.
- The document provides examples of testing methods, using matchers, stubs, focus/skip, and shared examples/contexts.
This document provides an overview of various topics related to optimizing performance in Ruby on Rails web applications, including:
- Different Rails application servers like Passenger, Unicorn, and Puma.
- Factors that affect web request performance like redirects, DNS lookups, and front-end loading.
- Database performance issues like N+1 queries and missing indexes that can be addressed through eager loading and adding indexes.
- Using caching at different levels like page, action, and fragment caching as well as ensuring caches are expired properly.
- Using background job queues like Resque to process long-running tasks asynchronously.
- The importance of monitoring applications and addressing performance issues that
The document provides an overview of jQuery, a popular JavaScript library, including its history and benefits such as easy DOM manipulation, AJAX capabilities, and cross-browser compatibility. It then demonstrates several jQuery functions and selectors for modifying HTML elements, handling events, and making AJAX requests to update content without page refreshes. Examples are given for selecting elements, updating styles, handling events like clicks, and validating form input with plugins.
Testing in Rails allows developers to write automated test suites using frameworks like Minitest and RSpec. These frameworks interact with the codebase to run tests from the command line and check that code works as expected. Tests can verify functionality when code is initially written and also help prevent breaks when code is refactored. Test-driven development involves writing tests before code so that tests guide code implementation.
The document discusses RSpec, a behavior-driven development (BDD) framework for testing Ruby code. It describes how RSpec allows writing tests in a natural language style using "should" statements. Examples are provided for different types of RSpec tests, including model, controller, and view tests. Shared examples, custom matchers, and integration with Cucumber for writing tests in a storytelling format are also covered. The document concludes with information on installing and running RSpec and generating reports from test results.
CodeIgniter is an MVC framework that allows developers to build applications in a logical manner. It provides features like clean URLs, form validation, security protections, and image manipulation tools out of the box. While CodeIgniter does not enforce rigid structures, it enables organization of applications into models, views, and controllers. It aims to help developers write code faster without forcing atypical approaches. The framework has good documentation and an active community for support.
The document discusses setting up a basic online store application in Rails. It covers generating a Store controller, routing requests to the store index action, displaying a list of products from the database, adding styles with CSS, using Rails helpers like number_to_currency to format prices, and writing functional tests for the controller. Homework includes adding a date to the sidebar, experimenting with number formatting options, and writing tests for the products controller.
This document discusses Behavior-Driven Development (BDD) and automation testing using Cucumber. It provides an example of writing a Cucumber scenario to test logging into a system. It then demonstrates how to automate this scenario by writing step definitions in Ruby. The document also presents pros and cons of the BDD and Cucumber approach, and includes a demo of using Cucumber to test a web application and web services.
Excellent is a static analysis gem that finds the nasty lines in your code. It implements a comprehensive set of checks for possibly buggy parts of your app that would otherwise make it into your repo and eventually to the production server.
This document provides an overview of routing changes in Rails 3, including:
- Matching routes using "match" instead of "map.connect" and optional segments.
- Namespaces, scopes, and constraints for organizing and restricting routes.
- Default RESTful routes and generating resources.
- Redirects can now be specified as Rack apps or Procs.
- Mounting other Rack endpoints at specific paths.
This document provides an introduction and overview of Ruby on Rails, including: its history and initial release in 2004; the Model-View-Controller architecture and included components; installing and setting up a basic Rails application; scaffolding a product catalog with CRUD functionality; adding validation, testing, and pushing the application to Heroku for deployment. It then demonstrates expanding the application by adding a shopping cart and checkout functionality using additional scaffolds, models, and controllers.
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Caldera Labs
This document discusses using AngularJS to build single page applications for WordPress admin interfaces that use the WordPress REST API. It covers why this approach is beneficial, how to set it up using Angular routing, controllers, factories and HTTP requests to interact with the REST API. Benefits mentioned include making WordPress interfaces more modern and dynamic, empowering others to build plugins in a decentralized way, and the ease of transitioning to software as a service models. The document encourages readers to learn Angular and check out additional resources on the topic.
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
The document provides an overview of a workshop on using the WordPress REST API and AngularJS. The workshop will cover REST API fundamentals, building custom REST APIs, unit testing APIs, and getting started with AngularJS by building controllers, templates, services, and factories. Attendees will learn through hands-on examples and code walkthroughs applied to real world projects.
Simplifying Code: Monster to Elegant in 5 Stepstutec
The document discusses techniques for refactoring code, including intention revealing methods, null objects, and replacing large methods with method objects. Intention revealing methods transform comments into descriptive method names to improve code readability. Null objects avoid null values and unnecessary conditionals. Large methods can be refactored by extracting the logic into a new class. The goal of refactoring is to improve code quality, shared understanding, and prevent bugs and performance issues.
This document discusses using RSpec for testing Rails applications. It covers installing RSpec and RSpec-rails, generating Rails projects with different frameworks and databases, generating scaffolds for models, running tests, and using RSpec matchers, stubs, mocks and other features for testing controllers, models, views and test coverage. It also introduces the autotest tool for automatically running tests on file changes.
RSpec is a testing framework for Ruby that supports behavior-driven development (BDD). It allows writing tests in a descriptive manner using plain English "examples" and "expectations". RSpec tests isolate the unit being tested using mocks and stubs. This allows writing true unit tests that focus on interactions between objects. RSpec provides tools like should and matchers for writing expectations as well as a mocking framework for stubbing method calls.
Introduction to ATDD with Cucumber and RSpecKenta Murata
This document discusses an introduction to acceptance test-driven development (ATDD) using Cucumber and RSpec. It explains that ATDD involves collaborating with stakeholders to write automated acceptance tests before development begins. The tests describe features and scenarios in a way that stakeholders can understand. Cucumber uses a plain language format to define tests and map them to code via step definitions. RSpec is also used for unit testing. The document provides examples of Cucumber feature files and touches on integrating Cucumber with RSpec during the development process.
This document provides an overview of RSpec testing for Rails applications. It discusses installing and generating RSpec files, different types of RSpec specs including model, controller, view, helper and routing specs. It covers spec syntax for expectations, matchers, factories and stubs. It also mentions features specs using Capybara, debugging techniques, JavaScript testing, and tools like DatabaseCleaner. The document is intended as a tutorial for setting up and writing different kinds of RSpec tests for a Rails application.
DevDay 2016: Dave Farley - Acceptance testing for continuous deliveryDevDay Dresden
Writing and maintaining a suite acceptance tests that can give you a high level of confidence in the behaviour and configuration of your system is a complex task. In this talk Dave will describe approaches to acceptance testing that allow teams to: work quickly and effectively; build excellent functional coverage for complex enterprise-scale systems; manage and maintain those tests in the face of change, and of evolution in both the codebase and the understanding of the business problem.
This answered the following questions, and more: How do you fail fast? How do you make your testing scalable? How do you isolate test cases from one-another? How do you maintain a working body of tests when you radically change the interface to your system?
This document provides an overview of software testing, including definitions, types of testing, and the software testing lifecycle. It defines software testing as a method to assess software functionality. The key points covered are:
- Software testing ensures software does what it's intended to do and remains functional after changes.
- Types of testing include unit, integration, system, and regression testing.
- The software testing lifecycle includes planning, developing test cases, executing tests, and closing test cycles.
- Cloud testing can reduce regression testing time by using virtualized hardware and software services.
Rspec and Capybara Intro Tutorial at RailsConf 2013Brian Sam-Bodden
Behavior-Driven Development and Acceptance Testing are heavily intertwined and in many aspects are one and the same. Both focus on starting at the outer layers of your application by concentrating on what matter to users; behavior. In this session/workshop we'll talk about how testing can be used both for specifying your application yet to be develop expected behavior and as accurate, running documentation that can be used to validate your stakeholder's acceptance criteria. We'll talk about the different types of testing and do a few hands-on exercises to flesh out a Rails application with RSpec and Capybara.
The document discusses best practices for unit testing, including:
1. Tests should follow a 3 step structure of prepare input, call method, check output. They should be fast, consistent, atomic, and have single responsibility.
2. Tests should isolate the environment, classes, and test instances to avoid dependencies. Mocking is recommended for environment isolation.
3. The best practices aim to make tests independent, fast, and easy to maintain through techniques like mocking and separating test logic from production code.
Unit Testing Concepts and Best PracticesDerek Smith
Unit testing involves writing code to test individual units or components of an application to ensure they perform as expected. The document discusses best practices for unit testing including writing atomic, consistent, self-descriptive tests with clear assertions. Tests should be separated by business module and type and not include conditional logic, loops, or exception handling. Production code should be isolated from test code. The goal of unit testing is to validate that code meets specifications and prevents regressions over time.
The document describes the key stages of the software testing life cycle (STLC), including contract signing, requirement analysis, test planning, test development, test execution, defect reporting, and product delivery. It provides details on the processes, documents, and activities involved in each stage. Risk analysis and bug/defect management processes are also summarized. Various test metrics and bug tracking tools that can be used are listed.
An Overview of User Acceptance Testing (UAT)Usersnap
What is User Acceptance Testing? Also known as UAT or UAT testing.
it's basically, a process of verifying that a solution works for the user.
And the key word here, is user. This is crucial, because they’re the people who will use the software on a daily basis. There are many aspects to consider with respect to software functionality. There’s unit testing, functional testing, integration testing, and system testing, amongst many others.
What Is User Acceptance Testing?
I’ll keep it simple; according to Techopedia, UAT (some people call it UAT testing as well) is:
User acceptance testing (UAT) is the last phase of the software testing process. During UAT, actual software users test the software to make sure it can handle required tasks in real-world scenarios, according to specifications. UAT is one of the final and critical software project procedures that must occur before newly developed software is rolled out to the market.
User acceptance testing (UAT), otherwise known as Beta, Application, or End-User Testing, is often considered the last phase in the web development process, the one before final installation of the software on the client site, or final distribution of it.
This document provides an overview of React, including initial reactions to it, fundamental concepts like components and one-way data flow, and how the virtual DOM works. Some key points covered include:
- Initial reactions to React were mixed, with some finding it "ugly" but others seeing benefits like separation of concerns with components.
- Everything in React is a component, with data flowing in one direction from parent to child via props. State is mutable within a component.
- By using a virtual DOM, React can efficiently update the real DOM by only making necessary changes, keeping the interface fast and pure.
The document outlines topics related to quality control engineering and software testing. It discusses key concepts like the software development lifecycle (SDLC), common SDLC models, software quality control, verification and validation, software bugs, and qualifications for testers. It also covers the quality control lifecycle, test planning, requirements verification techniques, and test design techniques like equivalence partitioning and boundary value analysis.
Introduction to Agile software testing - The 5th seminar in public seminar series from KMS Technology which have been delivering from 2011 in every two months
This document provides an overview of software testing concepts and processes. It discusses the importance of testing in the software development lifecycle and defines key terms like errors, bugs, faults, and failures. It also describes different types of testing like unit testing, integration testing, system testing, and acceptance testing. Finally, it covers quality assurance and quality control processes and how bugs are managed throughout their lifecycle.
The document discusses software testing concepts and processes. It covers definitions of testing, objectives of testing, types of defects and their costs. It also describes the typical software testing process which includes test planning, preparation, execution, reporting and defect tracking. Additionally, it discusses test strategies such as unit testing, integration testing, system testing and acceptance testing. The overall purpose is to provide an introduction and overview of basic software testing concepts.
Testing is the process of identifying bugs and ensuring software meets requirements. It involves executing programs under different conditions to check specification, functionality, and performance. The objectives of testing are to uncover errors, demonstrate requirements are met, and validate quality with minimal cost. Testing follows a life cycle including planning, design, execution, and reporting. Different methodologies like black box and white box testing are used at various levels from unit to system. The overall goal is to perform effective testing to deliver high quality software.
This document discusses various Rails concepts and tools including MVC, ActiveRecord, templates/helpers, libraries/plugins, deployment, and internationalization. It provides code examples for features like validations, callbacks, counter caches, named scopes, STI, polymorphic associations, pagination, Ajax forms, and exception handling. Various plugins are described like attachment_fu, acts_as_taggable, will_paginate, and facebox_render for adding functionality. Deployment topics covered include mailers, exception tracking, and Capistrano.
This document discusses using Ruby testing techniques with C# and ASP.NET. It begins by explaining how the mindset and practices of Ruby testing, such as test-driven development (TDD) and behavior-driven development (BDD), can be applied. It then provides examples of writing Ruby-style tests for C# code using tools like RSpec and describes testing strategies like sharing examples across tests. The document advocates an outside-in approach of writing acceptance tests first before unit tests.
This document provides an overview of test-driven development using RSpec and describes various RSpec features and techniques:
1. It explains the basic "red-green-refactor" process of test-driven development and provides a simple example of an RSpec spec.
2. It describes how to use mocks, stubs, and doubles in RSpec to isolate tests from external dependencies.
3. It outlines common RSpec expectations like .should, .should_receive, and others and how to configure and filter RSpec runs.
4. It briefly mentions using Capybara for feature tests and integrating RSpec with Cucumber, Autotest, and continuous integration tools.
The document discusses common mistakes and pitfalls when developing with Ruby on Rails, including:
1) Not understanding the difference between 'and' and '&&' operators and operator precedence issues this can cause.
2) Not sanitizing user input passed to functions like strip_tags, which can lead to security issues.
3) Caching controller actions without checking for initialized instance variables, which can cause crashes.
4) Issues with validating database uniqueness across multiple processes that can lead to duplicate entry errors.
5) Problems composing conditions for queries when categories or subcategories are empty.
6) Breaking the callback chain filter by returning from callbacks.
7) Perform
Using Geeklog as a Web Application FrameworkDirk Haun
Slides for the workshop "Using Geeklog as a Web Application Framework", as held at
- LinuxTag 2006, Wiesbaden, Germany, 2006-05-06
- PHP user group meeting, Stuttgart, Germany, 2006-05-10
- FrOSCon, Bonn, Germany, 2006-06-24
Given at YAPC::EU 2012
Dancer + WebSocket + AnyEvent + Twiggy
This in *not* a talk about doing a hello world in Dancer, as there are plenty of it. This is a real-life example of using Dancer to address a problem in an elegant and powerful way
At $job, we have cpan mirrors. We want them to stay a bit behind the real CPAN for stability, but we have a tool to update modules from the real CPAN to our mirrors. Cool.
I wanted to have a web interface to trigger it, and monitor the injection. This problem is not a typical one (blog, wiki, CRUD, etc). Here we have a long running operation that shall happen only one at a time, that generates logs to be displayed, with states that need keeping. In this regard, it's interesting to see how Dancer is versatile enough to address these situations with ease.
This talk details how I did that, the technology I used, and the full source code (which is quite short). I used Dancer + WebSocket + AnyEvent + Twiggy + some other stuff.
This talk doesn't require any particular knowledge beyond basic Perl, and very basic web server understanding.
User login functionality in a website is a pretty simple but compulsory component. In all modern dynamic websites, the client asks for a login and admin panel so that they can do basic tasks.
Today I will give you a simple and clean-looking login system with PHP and MySQL. We will maintain the login tracking with PHP Sessions and let Bootstrap make us a clean UI Design.
Why PHP? Because despite being ancient. As some developers believe. PHP is fundamental to our web.
Around 81.7% of the websites on the web use PHP as their server-side language.
And why not PHP?
PHP powers famous CMS(Content Management System) like WordPress and Joomla. Open Source OOPs frameworks like Laravel and CodeIgniter. And numerous others.
Reason: PHP is simple and clean to write. Easy-to-understand and beginner-friendly. Vast community support and adaptability toward developer needs.
Let’s what will do in this simple project:
-User Login Design with Bootstrap 5
- PHP code for MySQL Database
- Logic to process the login request
- Throw errors if the wrong entry of login credentials
- Redirect to Admin if successful request
- Conclusion
Forging a clean UI with Bootstrap for User Login
First, we create index.php and write our UI design with the latest Bootstrap 5. We added Google Fonts Poppins for making our UI look eye-catching. Whenever possible, we relied on CDN links because it keeps our code lightweight and less resource intensive.
Next, we do simple CSS styling in our style.css file. To make our plain background something fun to look at, I have added a small background image in webp format. Also, coded in background color as a backup in the case of legacy browsers that do not support webp format yet.
Build and Hook up your MySQL database
Before we start preceding the actual PHP logic part. We need a database for keeping a record of our login users. And the best choice of course is MySQL–why because it’s free and open source like PHP. Not to mention very beginner friendly.
First, go to your PHPMyAdmin whether you’re working online or in the local environment. And set up your database with a relevant name to your project.
After the Database is created. Setup a table named users which has mainly four columns we need: id, email, password, and active. We can also execute the below SQL code in the PHPMyAdmin SQL tab and this will generate our table “users”.
Now, we can insert user login details by running the following SQL code. We are hard coding this now. But we can create a PHP code for the signup process later. First, we must deploy our user login system.
Next in line, we hook up a connection between MySQL and PHP:
Now our UI and database are set. Next, we tackle our User Login process head-on! Yay! I am excited!
This document provides a tutorial on creating a simple login/logout application using Grails. It discusses creating a Grails application and User controller. It describes customizing the login page view and adding a login form. It then covers creating the login action to handle form submission, adding validation, and using flash scope to display messages. The tutorial also demonstrates keeping the login status in the session, creating a logout action, and conditionally displaying the login form or logout link based on login status. Styling and other Grails resources are also briefly mentioned.
This document provides an overview of adding interactivity to Plone sites using JavaScript and various Plone-specific tools. It discusses including JavaScript via the resource registry and browser resources, using the Kinetic Style Sheets (KSS) framework to add behaviors with CSS syntax, common JavaScript libraries, debugging techniques, and notes that KSS may be removed from core Plone in future versions due to its large size and lack of adoption.
This document discusses using Cucumber and Capybara for behavior-driven development (BDD) testing in Ruby on Rails applications. It provides an overview of Cucumber for writing acceptance tests as plain text scenarios. It demonstrates defining a sample user login feature and scenario, and describes how to write step definitions using Capybara's domain-specific language to simulate user interactions like filling forms and clicking buttons.
Describes Outside-In development and Behvaiour Driven Development. Illustrates basic Cucumber usage within a Rails app and then goes over more advanced topics such as JS as web services.
This document discusses the history and future of JSF and Ajax. It begins with an overview of JSF and how it works. It then discusses early approaches to adding Ajax functionality to JSF such as Shale Remoting and Dynamic Faces. Next, it covers component libraries that integrated Ajax more fully like Ajax4JSF, Apache Trinidad, and ICEFaces. It concludes by looking ahead to further improvements in JSF 2.0.
Building Better Applications with Data::ManagerJay Shirley
The document discusses tools for managing form data and validation. It introduces Data::Manager, which provides a way to manage incoming data and validation rules across multiple scopes or sections. Data::Manager uses Data::Verifier under the hood to validate data according to defined rules. It provides methods to verify data, check for errors, and retrieve validation results. The document emphasizes usability, reliability, and hiding complexity through a clean API.
The document provides an introduction and overview of Ruby on Rails, including its key components such as the MVC framework, ActiveRecord for object-relational mapping, scaffolding for rapid prototyping, and deployment considerations. It discusses Rails' advantages like rapid development speed and native support for best practices like MVC, and highlights resources for learning more.
This document summarizes several common Rails antipatterns including monolithic controllers, fat controllers, voyeuristic models, duplicate code, and messy migrations. It provides examples of each antipattern and recommendations for refactoring code to avoid them, such as extracting logic into modules, using service objects, and avoiding external dependencies in migrations.
Introduction of Cybersecurity with OSS at Code Europe 2024Hiroshi SHIBATA
I develop the Ruby programming language, RubyGems, and Bundler, which are package managers for Ruby. Today, I will introduce how to enhance the security of your application using open-source software (OSS) examples from Ruby and RubyGems.
The first topic is CVE (Common Vulnerabilities and Exposures). I have published CVEs many times. But what exactly is a CVE? I'll provide a basic understanding of CVEs and explain how to detect and handle vulnerabilities in OSS.
Next, let's discuss package managers. Package managers play a critical role in the OSS ecosystem. I'll explain how to manage library dependencies in your application.
I'll share insights into how the Ruby and RubyGems core team works to keep our ecosystem safe. By the end of this talk, you'll have a better understanding of how to safeguard your code.
Skybuffer SAM4U tool for SAP license adoptionTatiana Kojar
Manage and optimize your license adoption and consumption with SAM4U, an SAP free customer software asset management tool.
SAM4U, an SAP complimentary software asset management tool for customers, delivers a detailed and well-structured overview of license inventory and usage with a user-friendly interface. We offer a hosted, cost-effective, and performance-optimized SAM4U setup in the Skybuffer Cloud environment. You retain ownership of the system and data, while we manage the ABAP 7.58 infrastructure, ensuring fixed Total Cost of Ownership (TCO) and exceptional services through the SAP Fiori interface.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfMalak Abu Hammad
Discover how MongoDB Atlas and vector search technology can revolutionize your application's search capabilities. This comprehensive presentation covers:
* What is Vector Search?
* Importance and benefits of vector search
* Practical use cases across various industries
* Step-by-step implementation guide
* Live demos with code snippets
* Enhancing LLM capabilities with vector search
* Best practices and optimization strategies
Perfect for developers, AI enthusiasts, and tech leaders. Learn how to leverage MongoDB Atlas to deliver highly relevant, context-aware search results, transforming your data retrieval process. Stay ahead in tech innovation and maximize the potential of your applications.
#MongoDB #VectorSearch #AI #SemanticSearch #TechInnovation #DataScience #LLM #MachineLearning #SearchTechnology
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on integration of Salesforce with Bonterra Impact Management.
Interested in deploying an integration with Salesforce for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Building Production Ready Search Pipelines with Spark and MilvusZilliz
Spark is the widely used ETL tool for processing, indexing and ingesting data to serving stack for search. Milvus is the production-ready open-source vector database. In this talk we will show how to use Spark to process unstructured data to extract vector representations, and push the vectors to Milvus vector database for search serving.
Have you ever been confused by the myriad of choices offered by AWS for hosting a website or an API?
Lambda, Elastic Beanstalk, Lightsail, Amplify, S3 (and more!) can each host websites + APIs. But which one should we choose?
Which one is cheapest? Which one is fastest? Which one will scale to meet our needs?
Join me in this session as we dive into each AWS hosting service to determine which one is best for your scenario and explain why!
Taking AI to the Next Level in Manufacturing.pdfssuserfac0301
Read Taking AI to the Next Level in Manufacturing to gain insights on AI adoption in the manufacturing industry, such as:
1. How quickly AI is being implemented in manufacturing.
2. Which barriers stand in the way of AI adoption.
3. How data quality and governance form the backbone of AI.
4. Organizational processes and structures that may inhibit effective AI adoption.
6. Ideas and approaches to help build your organization's AI strategy.
A Comprehensive Guide to DeFi Development Services in 2024Intelisync
DeFi represents a paradigm shift in the financial industry. Instead of relying on traditional, centralized institutions like banks, DeFi leverages blockchain technology to create a decentralized network of financial services. This means that financial transactions can occur directly between parties, without intermediaries, using smart contracts on platforms like Ethereum.
In 2024, we are witnessing an explosion of new DeFi projects and protocols, each pushing the boundaries of what’s possible in finance.
In summary, DeFi in 2024 is not just a trend; it’s a revolution that democratizes finance, enhances security and transparency, and fosters continuous innovation. As we proceed through this presentation, we'll explore the various components and services of DeFi in detail, shedding light on how they are transforming the financial landscape.
At Intelisync, we specialize in providing comprehensive DeFi development services tailored to meet the unique needs of our clients. From smart contract development to dApp creation and security audits, we ensure that your DeFi project is built with innovation, security, and scalability in mind. Trust Intelisync to guide you through the intricate landscape of decentralized finance and unlock the full potential of blockchain technology.
Ready to take your DeFi project to the next level? Partner with Intelisync for expert DeFi development services today!
Monitoring and Managing Anomaly Detection on OpenShift.pdfTosin Akinosho
Monitoring and Managing Anomaly Detection on OpenShift
Overview
Dive into the world of anomaly detection on edge devices with our comprehensive hands-on tutorial. This SlideShare presentation will guide you through the entire process, from data collection and model training to edge deployment and real-time monitoring. Perfect for those looking to implement robust anomaly detection systems on resource-constrained IoT/edge devices.
Key Topics Covered
1. Introduction to Anomaly Detection
- Understand the fundamentals of anomaly detection and its importance in identifying unusual behavior or failures in systems.
2. Understanding Edge (IoT)
- Learn about edge computing and IoT, and how they enable real-time data processing and decision-making at the source.
3. What is ArgoCD?
- Discover ArgoCD, a declarative, GitOps continuous delivery tool for Kubernetes, and its role in deploying applications on edge devices.
4. Deployment Using ArgoCD for Edge Devices
- Step-by-step guide on deploying anomaly detection models on edge devices using ArgoCD.
5. Introduction to Apache Kafka and S3
- Explore Apache Kafka for real-time data streaming and Amazon S3 for scalable storage solutions.
6. Viewing Kafka Messages in the Data Lake
- Learn how to view and analyze Kafka messages stored in a data lake for better insights.
7. What is Prometheus?
- Get to know Prometheus, an open-source monitoring and alerting toolkit, and its application in monitoring edge devices.
8. Monitoring Application Metrics with Prometheus
- Detailed instructions on setting up Prometheus to monitor the performance and health of your anomaly detection system.
9. What is Camel K?
- Introduction to Camel K, a lightweight integration framework built on Apache Camel, designed for Kubernetes.
10. Configuring Camel K Integrations for Data Pipelines
- Learn how to configure Camel K for seamless data pipeline integrations in your anomaly detection workflow.
11. What is a Jupyter Notebook?
- Overview of Jupyter Notebooks, an open-source web application for creating and sharing documents with live code, equations, visualizations, and narrative text.
12. Jupyter Notebooks with Code Examples
- Hands-on examples and code snippets in Jupyter Notebooks to help you implement and test anomaly detection models.
Main news related to the CCS TSI 2023 (2023/1695)Jakub Marek
An English 🇬🇧 translation of a presentation to the speech I gave about the main changes brought by CCS TSI 2023 at the biggest Czech conference on Communications and signalling systems on Railways, which was held in Clarion Hotel Olomouc from 7th to 9th November 2023 (konferenceszt.cz). Attended by around 500 participants and 200 on-line followers.
The original Czech 🇨🇿 version of the presentation can be found here: https://www.slideshare.net/slideshow/hlavni-novinky-souvisejici-s-ccs-tsi-2023-2023-1695/269688092 .
The videorecording (in Czech) from the presentation is available here: https://youtu.be/WzjJWm4IyPk?si=SImb06tuXGb30BEH .
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on automated letter generation for Bonterra Impact Management using Google Workspace or Microsoft 365.
Interested in deploying letter generation automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Your One-Stop Shop for Python Success: Top 10 US Python Development Providersakankshawande
Simplify your search for a reliable Python development partner! This list presents the top 10 trusted US providers offering comprehensive Python development services, ensuring your project's success from conception to completion.
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
RSpec User Stories
1. RSpec and User Stories
A step by step tutorial
By Rahoul Baruah
http://www.brightbox.co.uk
Released under the Creative Commons Attribution Share-Alike Licence
2. What is RSpec?
Behaviour Driven Development
An evolution of Test Driven Development
Concentrates on the “behaviour” of your
system
Specify the behaviour first, implement it
second, refactor it third.
3. What are User Stories?
Acceptance Tests for RSpec
Describe the functionality of your application
in terms your customer will understand
Prove that the application does what it is
supposed to.
4. A Simple Authentication System
Write the feature
Write verification code for the feature
Specify the controller
Implement the controller
Specify the models
Implement the models
Verify the feature works as required
Refactor
5. Write our Feature
Write our feature and save it as features/
allow-a-user-to-login.feature
Show it to the customer and have it approved
Run rake features
6. Feature: Allow a User to log in
As a user,
I want to log in,
So I can see my stuff
Scenario: Successful login
Given a user called Dave with a password of secret
And 15 items of stuff
When I log in as Dave with password secret
Then I should see the Dashboard page
And it should list my 15 items of stuff
Scenario: Unsuccessful login
Given a user called Dave with a password of secret
When I log in as Dave with password potato
Then I should see the Login page
And I should see a message saying “an incorrect username or
password was supplied”
7. rake features
When we run ‘rake features’ it tells us that
none of the features are implemented
So we start with the first step and implement
that
8. Steps - proving a feature works
Create Ruby files, registration-steps.rb and
session-steps.rb, in features/steps
These contain the code verifying that the
feature works as expected
9. registration and session steps
Given /^a user called (.*) with a password of (.*)$/ do | username, password |
user = User.find_by_username username
user.destroy unless user.nil?
visits '/registrations/new'
fills_in 'User name', :with => username
fills_in 'Password', :with => password
fills_in 'Password Confirmation', :with => password
clicks_button 'Register'
end
When /^I log in as (.*) with password (.*)$/ do | username, password |
visits '/sessions/new'
fills_in 'User name', :with => username
fills_in 'Password', :with => password
clicks_button 'Log in'
end
Then /^I should see the Dashboard page$/ do
response.should redirect_to('/dashboard')
end
Use Webrat to define our interactions with the application
Use RSpec to check the responses from the application
10. Specify our Controller
‘rake features’ fails
So we need to start writing some code to make it pass
But before we write any code, we need a specification
So we run…
ruby script/generate rspec_controller Registrations
…to build a blank controller and specification
Now to implement the RegistrationsController.
Similar work needs to be done with the
SessionsController for actually logging in.
11. describe RegistrationsController do
describe quot;GET newquot; do
it quot;should show the form to allow someone to registerquot; do
on_getting :new do
expect_to_create_a_blank_user
end
response.should be_success
response.should render_template('registrations/new')
end
describe quot;POST createquot; do
it quot;should create and log in a new userquot; do
on_posting_to :create, :user => { quot;somequot; => :values } do
expect_to_build_a_new_user_with quot;somequot; => :values
expect_to_save_the_new_user_successfully
end
controller.current_user.should == @user
end
it quot;should redirect to the users dashboardquot; do
on_posting_to :create, :user => { quot;somequot; => :values } do
expect_to_build_a_new_user_with quot;somequot; => :values
expect_to_save_the_new_user_successfully
end
12. Cont’d…
it quot;should fail to create a new user if given invalid valuesquot; do
on_posting_to :create, :user => { quot;somequot; => :values } do
expect_to_build_a_new_user_with quot;somequot; => :values
expect_to_fail_to_save_the_new_user
end
controller.current_user.should be_blank
end
it quot;should reshow the registration form if given invalid valuesquot; do
on_posting_to :create, :user => { quot;somequot; => :values } do
expect_to_build_a_new_user_with quot;somequot; => :values
expect_to_fail_to_save_the_new_user
end
response.should render_template('/sessions/new')
flash[:error].should == 'There were some errors when registering your details'
end
end
end
13. Specification for new registrations
Use helper methods to make the specification easier to read
Use mock objects so we are testing just the controller, not the
(non-existent) models
Note how we can supply quot;somequot; => :values for
the :registration parameter. As we are not using real
models, the actual fields do not matter; what counts is how
the controller behaves in response to certain actions.
14. def expect_to_create_a_blank_user
@user = mock_model User
User.should_receive(:new).and_return(@user)
end
def expect_to_build_a_new_user_with parameters
@user = mock_model User
User.should_receive(:new).with(parameters).and_return(@user)
end
def expect_to_save_the_new_user_successfully
@user.should_receive(:save!).and_return(true)
end
def expect_to_fail_to_save_the_new_user
prepare_for_errors_on @user
@user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user))
end
The helpers build a mock user
We tell the mock to expect certain method calls and return the
correct responses
15. Implement the Controller
We do need to build a model…
ruby script/generate rspec_model User
…so that our steps will run
Remove the < ActiveRecord::Base from the definition for now
(so that ActiveRecord does not complain about our lack of
database tables)
But we don’t implement anything in it yet; our controller
specification is using mocks so does not actually need a real
object
We also need to add some routes to get things moving…
map.resources :registrations
map.resources :sessions
map.resource :dashboard
16. Implementing the Controller
class RegistrationsController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new params[:user]
@user.save!
redirect_to dashboard_path
rescue ActiveRecord::RecordInvalid
flash[:error] = 'There were some errors when registering your details'
render :template => 'registrations/new', :status => 422
end
end
The implementation is pretty simple, which is exactly as it
should be.
17. Specifying the Model
Now we have our controller behaving as
specified we need to specify the behaviour of
our User model
We have already generated the RSpec files, we
just need to tell it how we expect a User to
behave.
18. Specifying the Model
We write the specs
Update the migration to deal with the fields we
need
We switch the model back so that it descends
from ActiveRecord::Base
We run the migration
We implement the model
19. Specifying the Model
First attempt…
describe User do
it quot;should have a usernamequot; do
@user = User.new :username => ''
@user.should_not be_valid
@user.should have(1).errors_on(:username)
end
it quot;should have a unique usernamequot; do
@first_user = User.create! :username => 'arthur', :password =>
'12345', :password_confirmation => '12345'
@second_user = User.new :username => 'arthur'
@second_user.should_not be_valid
@second_user.should have(1).errors.on(:username)
end
Cont’d…
20. Cont’d…
it quot;should confirm the password before savingquot; do
@user = User.new :password => 'secret', :password_confirmation => 'notsecret'
@user.should_not be_valid
@user.should have(1).errors_on(:password)
end
it quot;should encrypt the password before saving to the databasequot; do
PasswordEncrypter.should_receive(:encrypt).with('12345').and_return('3ncrypt3d')
@user = User.new :username => 'arthur', :password => '12345', :password_confirmation
=> '12345'
@user.save!
@user.encrypted_password.should == '3ncrypt3d'
end
end
21. Specifying the Model
There are two areas of the specification that “smell
bad”
Both “it should have a unique username” and “it should
encrypt the password before saving to the database”
require a valid object to be saved; which in turn
require knowledge of the object beyond that individual
specification clause
Ideally this would not be necessary but is a problem
with the ActiveRecord pattern; mixing business logic
and persistence logic in a single class
22. The (imperfect) solution is to use object
‘factories’ that encapsulate knowledge of a
valid model.
We are still spreading that knowledge outside
of the specification but at least it is a single
place to make that change (usually in spec/
spec_helper.rb)
23. describe User do
it quot;should have a usernamequot; do
@user = a User, :username => ''
@user.should_not be_valid
@user.should have(1).errors_on(:username)
end
it quot;should have a unique usernamequot; do
@first_user = a_saved User, :username => ‘arthur’
@second_user = a User, :username => 'arthur'
@second_user.should_not be_valid
@second_user.should have(1).errors.on(:username)
end
it quot;should confirm the password before savingquot; do
@user = a User, :password => 'secret', :password_confirmation => 'notsecret'
@user.should_not be_valid
@user.should have(1).errors_on(:password)
end
24. Rewritten to use “a Something” and “a_saved
Something” as an object factory
Each specification clause only specifies the
information it needs.
The factory ensures that the rest of the object
is valid.
25. Acceptance
By now we should have done enough to let the
first step in our story pass its acceptance test
rake features will prove it
That should be all we need to do for that
particular step - any extra development is
unnecessary as it has not been requested by
the customer
However, we can now safely refactor the code,
to organise it better, safe in the knowledge
that we can prove that it still does what is
required without breakages.
26. Appendix
We have a fork of RSpec for Rails that provides a set of helper
methods: prepare_for_errors_on, on_getting,
on_posting_to, on_putting_to and on_deleting_from
See http://github.com/rahoulb/rspec-rails/wikis/home
We are working on an object factory that makes building
models (without full knowledge of their internals) a bit
simpler…
Object.factory.when_creating_a User, :auto_generate
=> :username, :auto_confirm => :password
@user = a User
@user = a_saved User # as above but auto-saves the user
@user.should be_valid
See http://github.com/rahoulb/object-factory/wikis (although
at the time of writing, November 2008, this is not quite ready)