The base tool used for testing in Rails Makes tests easier on the eyes & fingers Expressive acceptance test library Behavior driven testing framework Plain text based BDD testing tool
An example feature
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
The feature name
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
The feature definition
Feature: Find love
In order to find love
I want to search the internet
Scenario: Searching for JS.Class docs Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
An example scenario
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
The scenario name
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
Given . . .
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
When . . .
Feature: Fidn love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
Then . . .
Feature: Find love
In order to find love
I want to search the internet
Scenario: looking (in all the wrong places) Given I have opened "http://www.google.com/" When I search for "love" Then I should see a link to "http://zombieharmony.com/" -> with text "Yes, even you can find love!"
The step definitions
Given /^I have opened " ([^"]*) "$/ do | url |
visit url
end
When /^I search for " ([^"]*) "$/ do | query |
fill_in 'q' , :with => query
click_button 'Google Search'
end
Then /^I should see a link to " ([^"]*) " with text " ([^"]*) "$/ do | url , text |
response_body.should have_selector( "a[href='#{ url }']" ) do |element|
element .should contain( text )
end
end
Given definition
Given /^I have opened " ([^"]*) "$/ do | url |
visit url
end
When /^I search for "([^"]*)"$/ do |query|
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to "([^"]*)" with text "([^"]*)"$/ do |url, text|
response_body.should have_selector("a[href='#{ url }']") do |element|
element.should contain(text)
end
end
When definition
Given /^I have opened "([^"]*)"$/ do |url|
visit url
end
When /^I search for " ([^"]*) "$/ do | query |
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to "([^"]*)" with text "([^"]*)"$/ do |url, text|
response_body.should have_selector("a[href='#{ url }']") do |element|
element.should contain(text)
end
end
Then definition
Given /^I have opened "([^"]*)"$/ do |url|
visit url
end
When /^I search for "([^"]*)"$/ do |query|
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to " ([^"]*) " with text " ([^"]*) "$/ do | url , text |
response_body.should have_selector( "a[href='#{ url }']" ) do |element|
element. should contain( text )
end
end
Cucumber
Given /^I have opened "([^"]*)"$/ do | url |
visit url
end
When /^I search for "([^"]*)"$/ do | query |
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to "([^"]*)" with text "([^"]*)"$/ do | url , text |
response_body.should have_selector("a[href='#{ url }']") do |element|
element.should contain(text)
end
end
webrat
Given /^I have opened "([^"]*)"$/ do |url|
visit url
end
When /^I search for "([^"]*)"$/ do |query|
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to "([^"]*)" with text "([^"]*)"$/ do |url, text|
response_body.should have_selector ("a[href='#{ url }']") do |element|
element.should contain (text)
end
end
RSpec
Given /^I have opened "([^"]*)"$/ do |url|
visit url
end
When /^I search for "([^"]*)"$/ do |query|
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should see a link to "([^"]*)" with text "([^"]*)"$/ do |url, text|
response_body.should have_selector("a[href='#{ url }']") do |element|
element. should contain(text)
end
end
Controller test
describe LoveController do
it { should route( :get , 'search' ).to( :action => :find ) }
describe 'lookin for love' do
before { get :find , :q => 'someone to hold me - ever so gently' }
it { should respond_with 404 }
it { should respond_with_content_type 'text/html' }
end
end
RSpec
describe LoveController do
it { should route(:get, 'search').to(:action => :find) }
describe 'lookin for love' do
before { get :find, :q => 'someone to hold me - ever so gently' }
it { should respond_with 404 }
it { should respond_with_content_type 'text/html' }
end
end
Shoulda
describe LoveController do
it { should route (:get, 'search'). to (:action => :find) }
describe 'lookin for love' do
before { get :find, :q => 'someone to hold me - ever so gently' }
it { should respond_with 404 }
it { should respond_with_content_type 'text/html' }
0 comments
Post a comment