SlideShare a Scribd company logo
Rails testing tools Agile - the Rails Way
Testing Test::Unit Shoulda webrat RSpec Cucumber 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' } end end
When to use what For user acceptance (view) testing: Cucumber webrat RSpec For functional (controller) testing: Rspec Shoulda Factory Girl (not covered here) For unit (model) testing: Shoulda Test::Unit
Pimp my project Pimp my data: Factory Girl Mocha Fixtures Pimp my code: Autotest (part of ZenTest) RCov (code coverage tool) metric_fu (if ninjas created reports)
Comparing Java & Ruby Ruby Community driven Surgical tools Duck typing Wild west 15 years old Java Committee driven  Swiss Army Knife  Static typing  JCP  14 years old

More Related Content

PPT
Ruby testing tools
PPT
Lecture 6 - Comm Lab: Web @ ITP
ODP
Future Of Web Languages
PPT
Mashups & APIs
PDF
Owl and The Hummingbird - Ontology and SEO
KEY
Paul Bunkham at WP-Brighton 2011 - WordPress and eCommerce
PDF
Integration Test With Cucumber And Webrat
Ruby testing tools
Lecture 6 - Comm Lab: Web @ ITP
Future Of Web Languages
Mashups & APIs
Owl and The Hummingbird - Ontology and SEO
Paul Bunkham at WP-Brighton 2011 - WordPress and eCommerce
Integration Test With Cucumber And Webrat

Similar to Ruby testing tools (20)

PPT
Selenium and Cucumber Selenium Conf 2011
PPT
Cucumber Presentation Kiev Meet Up
PPTX
Behavior Driven Development Testing (BDD)
PDF
Automated Testing with Ruby
PPTX
Web Services
 
PDF
Testing Merb
PPTX
Testing ASP.net Web Applications using Ruby
PDF
Behaviour driven infrastructure
PPTX
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
PPT
Integration and Acceptance Testing
PPTX
Cucumber
DOCX
Cucumber testing
DOCX
Cucumber testing
ZIP
Unit Tests Aren't Enough
PPT
What you can do In WatiR
PDF
Acceptance Testing with Webrat
PPTX
Cucumber From the Ground Up - Joseph Beale
PDF
Watir web automated tests
PPTX
BDD / cucumber /Capybara
Selenium and Cucumber Selenium Conf 2011
Cucumber Presentation Kiev Meet Up
Behavior Driven Development Testing (BDD)
Automated Testing with Ruby
Web Services
 
Testing Merb
Testing ASP.net Web Applications using Ruby
Behaviour driven infrastructure
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
Integration and Acceptance Testing
Cucumber
Cucumber testing
Cucumber testing
Unit Tests Aren't Enough
What you can do In WatiR
Acceptance Testing with Webrat
Cucumber From the Ground Up - Joseph Beale
Watir web automated tests
BDD / cucumber /Capybara
Ad

Ruby testing tools

  • 1. Rails testing tools Agile - the Rails Way
  • 2. Testing Test::Unit Shoulda webrat RSpec Cucumber 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
  • 3. 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!"
  • 4. 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!"
  • 5. 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!"
  • 6. 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!"
  • 7. 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!"
  • 8. 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!"
  • 9. 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!"
  • 10. 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!"
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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' } end end
  • 21. When to use what For user acceptance (view) testing: Cucumber webrat RSpec For functional (controller) testing: Rspec Shoulda Factory Girl (not covered here) For unit (model) testing: Shoulda Test::Unit
  • 22. Pimp my project Pimp my data: Factory Girl Mocha Fixtures Pimp my code: Autotest (part of ZenTest) RCov (code coverage tool) metric_fu (if ninjas created reports)
  • 23. Comparing Java & Ruby Ruby Community driven Surgical tools Duck typing Wild west 15 years old Java Committee driven Swiss Army Knife Static typing JCP 14 years old