Cucumber
is used for Behaviour Driven Development.
Cucumber
lets software development teams describe how software
should behave in plain text. The text is written in a
business-readable
domain-specific language
and serves as documentation, automated tests and development-aid -
all rolled into one format.
Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages.
Install
cucumber for Rails 3:
Install
Cucumber, Rspec-rails and capybara gem
sudo gem install cucumber-rails sudo gem install database_cleaner sudo gem install rspec-rails sudo gem install capybara
- Cucumber is a behavior driven development (BDD) framework in particular good for integration and functional tests
- RSpec is a behavior driven development (BDD) framework for low level testing in the Ruby language
- database_cleaner performs DB cleanup in testing
- capybara
simulating a browser, automating a browser or setting expectations
using the matchers.
Using Cucumber to test rails 3 application:
- Create
a new Rails application store
- Edit
the Gemfile
group :test, :development do gem 'rspec-rails' gem 'cucumber-rails' gem 'capybara' gem 'database_cleaner' end
bundle install
- Install
the cucumber skeleton files to a Rails 3 application.
$ rails generate cucumber:install
The cucumber-rails generator creates the directories:
features/step_definitions
features/support
The cucumber-rails generator
creates the files:
config/cucumber.yml
features/support/env.rb
lib/tasks/cucumber.rake
script/cucumber
rake db:create
rake db:migrate
- Run
the Cucumber features
Create cucumber features:
- Create
a Cucumber Feature for Rails 3 application testing
- Cucumber
Feature is the business user testing specification written in plain
English with a specific format
Feature: ... In order ... Some Actor ... Should ... Scenarior: ... Given ... And ... When ... AND ... Then ... AND ...Implement the testing steps and Rails model code for Cucumber on Rails :
- Create
Cucumber step definitions
- Cucumber
uses regular expression to match string and pass it to the step
definitions
- Run
Cucumber
$rake cucumber
An example might be the ability to manage companies:
Feature: Manage companies In order to keep track of companies A user Should be able to manage companies Scenario: Create a new company Given I am logged in When I create a new company named Acme Then I should see that a company named Acme exists features/ companies.feature steps/ company_steps.rb Given == Setup Given "I am logged in" do user = Factory(:user) visits new_session_path fills_in ‘Login’, :with => user.login fills_in ‘Password’, :with => user.password clicks_button ‘Login’ end Given "I am logged in" do user = Factory(:user) visits new_session_path fills_in 'Login', :with => user.login fills_in 'Password', :with => user.password clicks_button 'Login' end When == Change When "I create a new company named $name" do |name| visits new_company_path fills_in 'Name', :with => name clicks_button 'Create' end Then == Outcome Then "I should see that a company named $name exists" do |name| response.body.should =~ Regexp.new(name) end At every step you need to run cucumber and check for the result.
i was looking for Cucumber and finally landed up on your post..thanks for sharing that what i was looking for
ReplyDeleteror development company|hire ror developers|ruby application development
Nice post ! Thanks for sharing valuable information with us. Keep sharing..
ReplyDeleteRuby on Rails Online Training