Ruby testing tools
description
Transcript of Ruby testing tools
![Page 1: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/1.jpg)
Rails testing tools
Agile - the Rails Way
![Page 2: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/2.jpg)
Testing
•Test::Unit•Shoulda•webrat•RSpec•Cucumber
The base tool used for testing in Rails
Makes tests easier on the eyes & fingersExpressive acceptance test libraryBehavior driven testing frameworkPlain text based BDD testing tool
![Page 3: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/3.jpg)
An example featureFeature: 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!"
![Page 4: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/4.jpg)
The feature nameFeature: 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!"
![Page 5: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/5.jpg)
The feature definitionFeature: 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!"
![Page 6: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/6.jpg)
An example scenarioFeature: 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!"
![Page 7: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/7.jpg)
The scenario nameFeature: 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!"
![Page 8: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/8.jpg)
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!"
![Page 9: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/9.jpg)
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!"
![Page 10: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/10.jpg)
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!"
![Page 11: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/11.jpg)
The step definitionsGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 12: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/12.jpg)
Given definitionGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 13: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/13.jpg)
When definitionGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 14: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/14.jpg)
Then definitionGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 15: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/15.jpg)
CucumberGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 16: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/16.jpg)
webratGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 17: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/17.jpg)
RSpecGiven /^I have opened "([^\"]*)"$/ do |url| visit urlend
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) endend
![Page 18: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/18.jpg)
Controller testdescribe 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
![Page 19: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/19.jpg)
RSpecdescribe 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
![Page 20: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/20.jpg)
Shouldadescribe 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
![Page 21: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/21.jpg)
When to use whatFor 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
![Page 22: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/22.jpg)
Pimp my projectPimp my data:
•Factory Girl•Mocha•Fixtures
Pimp my code:•Autotest (part of ZenTest)•RCov (code coverage tool)•metric_fu (if ninjas created reports)
![Page 23: Ruby testing tools](https://reader035.fdocuments.us/reader035/viewer/2022062704/555a43fbd8b42a83368b523c/html5/thumbnails/23.jpg)
Comparing Java & RubyRuby
Community driven Surgical tools Duck typing Wild west 15 years old
JavaCommittee driven Swiss Army Knife
Static typing JCP
14 years old