Rails testing tools Agile - the Rails Way
Testing <ul><ul><li>Test::Unit </li></ul></ul><ul><ul><li>Shoulda </li></ul></ul><ul><ul><li>webrat </li></ul></ul><ul><ul...
An example feature <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search t...
The feature name <ul><li>Feature:  Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search th...
The feature definition <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to sear...
An example scenario <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search ...
The scenario name <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search th...
Given . . . <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the inte...
When . . . <ul><li>Feature: Fidn love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the inter...
Then . . . <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the inter...
The step definitions <ul><li>Given   /^I have opened &quot; ([^&quot;]*) &quot;$/  do | url | </li></ul><ul><li>visit  url...
Given definition <ul><li>Given   /^I have opened &quot; ([^&quot;]*) &quot;$/  do | url | </li></ul><ul><li>visit   url </...
When definition <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><u...
Then definition <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><u...
Cucumber <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/  do | url | </li></ul><ul><li>visit url </li></ul><ul><l...
webrat <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit  url </li></ul><ul><li>en...
RSpec <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><ul><li>end ...
Controller test <ul><li>describe LoveController   do </li></ul><ul><li>it   {   should route( :get ,   'search' ).to( :act...
RSpec <ul><li>describe LoveController   do </li></ul><ul><li>it   { should route(:get, 'search').to(:action => :find) } </...
Shoulda <ul><li>describe LoveController   do </li></ul><ul><li>it   {  should route (:get, 'search'). to (:action => :find...
When to use what <ul><li>For user acceptance (view) testing: </li></ul><ul><ul><li>Cucumber </li></ul></ul><ul><ul><li>web...
Pimp my project <ul><li>Pimp my data: </li></ul><ul><ul><li>Factory Girl </li></ul></ul><ul><ul><li>Mocha </li></ul></ul><...
Comparing Java & Ruby <ul><li>Ruby </li></ul><ul><li>Community driven </li></ul><ul><li>Surgical tools </li></ul><ul><li>D...
Upcoming SlideShare
Loading in …5
×

Ruby testing tools

2,577
-1

Published on

Some of the tools available with a small usage example

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,577
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby testing tools

  1. 1. Rails testing tools Agile - the Rails Way
  2. 2. Testing <ul><ul><li>Test::Unit </li></ul></ul><ul><ul><li>Shoulda </li></ul></ul><ul><ul><li>webrat </li></ul></ul><ul><ul><li>RSpec </li></ul></ul><ul><ul><li>Cucumber </li></ul></ul>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. 3. An example feature <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  4. 4. The feature name <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  5. 5. The feature definition <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: Searching for JS.Class docs Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  6. 6. An example scenario <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  7. 7. The scenario name <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  8. 8. Given . . . <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  9. 9. When . . . <ul><li>Feature: Fidn love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  10. 10. Then . . . <ul><li>Feature: Find love </li></ul><ul><li>In order to find love </li></ul><ul><li>I want to search the internet </li></ul>Scenario: looking (in all the wrong places) Given I have opened &quot;http://www.google.com/&quot; When I search for &quot;love&quot; Then I should see a link to &quot;http://zombieharmony.com/&quot; -> with text &quot;Yes, even you can find love!&quot;
  11. 11. The step definitions <ul><li>Given /^I have opened &quot; ([^&quot;]*) &quot;$/ do | url | </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot; ([^&quot;]*) &quot;$/ do | query | </li></ul><ul><li>fill_in 'q' , :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot; ([^&quot;]*) &quot; with text &quot; ([^&quot;]*) &quot;$/ do | url , text | </li></ul><ul><li>response_body.should have_selector( &quot;a[href='#{ url }']&quot; ) do |element| </li></ul><ul><li>element .should contain( text ) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  12. 12. Given definition <ul><li>Given /^I have opened &quot; ([^&quot;]*) &quot;$/ do | url | </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot;([^&quot;]*)&quot;$/ do |query| </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot;([^&quot;]*)&quot; with text &quot;([^&quot;]*)&quot;$/ do |url, text| </li></ul><ul><li>response_body.should have_selector(&quot;a[href='#{ url }']&quot;) do |element| </li></ul><ul><li>element.should contain(text) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  13. 13. When definition <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot; ([^&quot;]*) &quot;$/ do | query | </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot;([^&quot;]*)&quot; with text &quot;([^&quot;]*)&quot;$/ do |url, text| </li></ul><ul><li>response_body.should have_selector(&quot;a[href='#{ url }']&quot;) do |element| </li></ul><ul><li>element.should contain(text) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  14. 14. Then definition <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot;([^&quot;]*)&quot;$/ do |query| </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot; ([^&quot;]*) &quot; with text &quot; ([^&quot;]*) &quot;$/ do | url , text | </li></ul><ul><li>response_body.should have_selector( &quot;a[href='#{ url }']&quot; ) do |element| </li></ul><ul><li>element. should contain( text ) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  15. 15. Cucumber <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do | url | </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot;([^&quot;]*)&quot;$/ do | query | </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot;([^&quot;]*)&quot; with text &quot;([^&quot;]*)&quot;$/ do | url , text | </li></ul><ul><li>response_body.should have_selector(&quot;a[href='#{ url }']&quot;) do |element| </li></ul><ul><li>element.should contain(text) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  16. 16. webrat <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot;([^&quot;]*)&quot;$/ do |query| </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot;([^&quot;]*)&quot; with text &quot;([^&quot;]*)&quot;$/ do |url, text| </li></ul><ul><li>response_body.should have_selector (&quot;a[href='#{ url }']&quot;) do |element| </li></ul><ul><li>element.should contain (text) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  17. 17. RSpec <ul><li>Given /^I have opened &quot;([^&quot;]*)&quot;$/ do |url| </li></ul><ul><li>visit url </li></ul><ul><li>end </li></ul><ul><li>When /^I search for &quot;([^&quot;]*)&quot;$/ do |query| </li></ul><ul><li>fill_in 'q', :with => query </li></ul><ul><li>click_button 'Google Search' </li></ul><ul><li>end </li></ul><ul><li>Then /^I should see a link to &quot;([^&quot;]*)&quot; with text &quot;([^&quot;]*)&quot;$/ do |url, text| </li></ul><ul><li>response_body.should have_selector(&quot;a[href='#{ url }']&quot;) do |element| </li></ul><ul><li>element. should contain(text) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  18. 18. Controller test <ul><li>describe LoveController do </li></ul><ul><li>it { should route( :get , 'search' ).to( :action => :find ) } </li></ul><ul><li>describe 'lookin for love' do </li></ul><ul><li>before { get :find , :q => 'someone to hold me - ever so gently' } </li></ul><ul><li>it { should respond_with 404 } </li></ul><ul><li>it { should respond_with_content_type 'text/html' } </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  19. 19. RSpec <ul><li>describe LoveController do </li></ul><ul><li>it { should route(:get, 'search').to(:action => :find) } </li></ul><ul><li>describe 'lookin for love' do </li></ul><ul><li>before { get :find, :q => 'someone to hold me - ever so gently' } </li></ul><ul><li>it { should respond_with 404 } </li></ul><ul><li>it { should respond_with_content_type 'text/html' } </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  20. 20. Shoulda <ul><li>describe LoveController do </li></ul><ul><li>it { should route (:get, 'search'). to (:action => :find) } </li></ul><ul><li>describe 'lookin for love' do </li></ul><ul><li>before { get :find, :q => 'someone to hold me - ever so gently' } </li></ul><ul><li>it { should respond_with 404 } </li></ul><ul><li>it { should respond_with_content_type 'text/html' } </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  21. 21. When to use what <ul><li>For user acceptance (view) testing: </li></ul><ul><ul><li>Cucumber </li></ul></ul><ul><ul><li>webrat </li></ul></ul><ul><ul><li>RSpec </li></ul></ul><ul><li>For functional (controller) testing: </li></ul><ul><ul><li>Rspec </li></ul></ul><ul><ul><li>Shoulda </li></ul></ul><ul><ul><li>Factory Girl (not covered here) </li></ul></ul><ul><li>For unit (model) testing: </li></ul><ul><ul><li>Shoulda </li></ul></ul><ul><ul><li>Test::Unit </li></ul></ul>
  22. 22. Pimp my project <ul><li>Pimp my data: </li></ul><ul><ul><li>Factory Girl </li></ul></ul><ul><ul><li>Mocha </li></ul></ul><ul><ul><li>Fixtures </li></ul></ul><ul><li>Pimp my code: </li></ul><ul><ul><li>Autotest (part of ZenTest) </li></ul></ul><ul><ul><li>RCov (code coverage tool) </li></ul></ul><ul><ul><li>metric_fu (if ninjas created reports) </li></ul></ul>
  23. 23. Comparing Java & Ruby <ul><li>Ruby </li></ul><ul><li>Community driven </li></ul><ul><li>Surgical tools </li></ul><ul><li>Duck typing </li></ul><ul><li>Wild west </li></ul><ul><li>15 years old </li></ul><ul><li>Java </li></ul><ul><li>Committee driven </li></ul><ul><li>Swiss Army Knife </li></ul><ul><li>Static typing </li></ul><ul><li>JCP </li></ul><ul><li>14 years old </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×