SlideShare uma empresa Scribd logo
1 de 61
Baixar para ler offline
Aslak Hellesøy - Chief Scientist
http://cukes.info/
twitter.com/aslak_hellesoy
aslak.hellesoy@gmail.com
http://www.flickr.com/photos/cobalt/190883654/
http://www.flickr.com/photos/atomicshark/215358660
THIS IS
REALLY
BAD
NEWS!!
http://www.flickr.com/photos/jelles/2656101758/
85 committers
989 github followers
33000 gem downloads
30 related tools
http://www.flickr.com/photos/twose/887903401/
http://www.flickr.com/photos/purrr/126597849/
It s testing crack.
One serious stab
at using it and
I'm hooked.
features
step_definitions
support
env.rb
webrat_steps.rb
paths.rb
Installing Cucumber
$ gem install cucumber webrat rspec-rails rspec
$ script/generate cucumber
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) +
'/../../config/environment')
require 'cucumber/rails/world'
require 'cucumber/formatter/unicode'
Cucumber::Rails.use_transactional_fixtures
Cucumber::Rails.bypass_rescue
# Plus some more setup stuff.....
env.rb
webrat_steps.rb
Given /^I am on (.+)$/ do |page_name|
visit path_to(page_name)
end
When /^I press "([^"]*)"$/ do |button|
click_button(button)
end
Then /^I should see "([^"]*)"$/ do |text|
response.should contain(text)
end
module NavigationHelpers
# When /^I go to (.+)$/ do |page_name|
def path_to(page_name)
case page_name
when /the homepage/
'/'
when /^(.*)'s profile page$/i
user_profile_path(User.find_by_login($1))
else
raise "Can't find mapping for "#{page_name}""
end
end
end
World(NavigationHelpers)
paths.rb
Outside-In
Proposal notification
In order to reduce time spent on emailing
Administrators should be able to
mail proposal status to all owners
Given
When
Then
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Our First Feature
features/proposal_notification.feature
$ cucumber features/proposal_notification.feature
Run the feature
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
1 scenario (1 undefined)
4 steps (4 undefined)
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
1 scenario (1 undefined)
4 steps (4 undefined)
You can implement step definitions for undefined steps
with these snippets:
Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do
pending
end
Given /^the Cucumber proposal is approved$/ do
pending
end
When /^I send proposal emails$/ do
pending
end
Then /^aslak.hellesoy@gmail.com should get email$/ do
|string|
pending
end
Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do
pending
end
Given /^the Cucumber proposal is approved$/ do
pending
end
When /^I send proposal emails$/ do
pending
end
Then /^aslak.hellesoy@gmail.com should get email$/ do
|string|
pending
end
Step Definitions
features/step_definitions/proposal_steps.rb
features
step_definitions
support
env.rb
proposal_steps.rb
paths.rb
webrat_steps.rb
proposal_n..n.feature
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
TODO (Cucumber::Pending)
features/step_definitions/proposal_steps.rb:2
features/proposal_notification.feature:7
And the Cucumber proposal is approved
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do
Proposal.create!({
:email => 'aslak.hellesoy@gmail.com',
:title => 'Cucumber'
})
end
Do what Regexp says
features/step_definitions/proposal_steps.rb
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
uninitialized constant Proposal (NameError)
features/step_definitions/proposal_steps.rb:2
features/proposal_notification.feature:7
And the Cucumber proposal is approved
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
$ script/generate rspec_scaffold proposal 
email:string title:string approved:boolean
$ rake db:migrate db:test:clone
$ cucumber features --no-source
Make it Pass
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
TODO (Cucumber::Pending)
features/step_definitions/proposal_steps.rb:9
features/proposal_notification.feature:8
When I send proposal emails
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Given /^the Cucumber proposal is approved$/ do
proposal = Proposal.find_by_title('Cucumber')
proposal.approved = true
proposal.save!
end
Implement Intention
features/step_definitions/proposal_steps.rb
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send proposal emails
TODO (Cucumber::Pending)
features/step_definitions/proposal_steps.rb:15
features/proposal_notification.feature:9
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
When /^I send mass proposal email$/ do
visit(’admin’)
click_button("Send proposal emails")
end
Webrat
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send mass proposal email
No route matches "/admin" with {:method=>:get}
features/step_definitions/proposal_steps.rb:16
features/proposal_notification.feature:9
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Add the Controller
class AdminController < ApplicationController
def index
end
end
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send mass proposal email
Could not find link "Send proposal emails"
features/step_definitions/proposal_steps.rb:16
features/proposal_notification.feature:9
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Add the link
<%= link_to("Send proposal emails",
:action => 'mass_email') %>
And #mass_email
class AdminController < ApplicationController
def index
end
def mass_email
end
end
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send mass proposal email
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Email-Spec
Then /^... should get email$/ do |body|
open_email('aslak.hellesoy@gmail.com')
current_email.body.should == body
end
class AdminController < ApplicationController
def index
end
def mass_email
approved = Proposal.find_all_by_approved(true)
approved.each do |proposal|
AdminMailer.deliver_notification_email(proposal)
end
end
end
Controller
class AdminMailer < ActionMailer::Base
def notification_email(proposal)
recipients proposal.email
from "confreg@oreilly.com"
subject "Your Railsconf proposal"
body :proposal => proposal
end
end
Mailer
Hi <%= @proposal.email %>
Congratulations, <%= @proposal.title %> was accepted.
See you at RailsConf!
Mailer template
Feature: Proposal notification
In order to reduce time spent on emailing
Administrators should be able to mail
all proposals owners depending on status
Scenario: Email accepted proposal
Given aslak.hellesoy@gmail.com proposed Cucumber
And the Cucumber proposal is approved
When I send mass proposal email
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Scenarios? Steps?
Steps & Step Definitions
Given aslak.hellesoy@gmail.com proposed Cucumber
Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do
end
Step == Method invocation
Step Definition == Method defnition
Regexp group arguments
Given aslak.hellesoy@gmail.com proposed Cucumber
Given /^(.+) proposed (.+)$/ do |email, proposal_name|
end
Given aslak.hellesoy@gmail.com proposed Cucumber
$CUCUMBER_COLORS
Quoted arguments
Given I have "22" cukes in my belly
Given /^I have "([^"]*)" cukes in my belly$/ do |n|
end
Given I have "2" cukes in my belly
Multiline args (String)
Then aslak.hellesoy@gmail.com should get email
"""
Hi aslak.hellesoy@gmail.com
Congratulations, Cucumber was accepted.
See you at RailsConf!
"""
Then /^(.+) should get email$/ do |email, body|
end
Multiline args (Tables)
Given the following proposals
| email | title |
| aslak.hellesoy@gmail.com | Cucumber |
| bryan@brynary.com | Webrat |
Given /the following proposals$/ do |proposals|
Proposal.create!(proposals.hashes)
end
Scenario Outline: Email accepted proposals
Given the following proposals
| email | title |
| aslak.hellesoy@gmail.com | Cucumber |
| bryan@brynary.com | Webrat |
And the <proposal> proposal is approved
When I send proposal emails
Then <email> should <what>
Examples:
| proposal | email | what |
| Cucumber | aslak.hellesoy@gmail.com | get email |
| Cucumber | bryan@brynary.com | not get email |
| Webrat | bryan@brynary.com | get email |
Scenario Outline
OH HAI: STUFFING
MISHUN: CUCUMBR
I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ
WEN I EAT 2 CUCUMBRZ
DEN I HAZ 2 CUCUMBERZ IN MAH BELLY
AN IN TEH END 1 CUCUMBRZ KTHXBAI
$ cucumber -l en-lol stuffing.feature
AIL WITH STYLF E
Then /^I should have "(d+)" cukes my belly$/ do |cukes|
@belly.cukes.length.should == cukes.to_i
end
RSpec
Then /^I should have "(d+)" cukes my belly$/ do |cukes|
@belly.should have(cukes.to_i).cukes
end
Kosher RSpec
Then /^I should have "(d+)" cukes my belly$/ do |cukes|
assert_equal(@cukes.to_i, @belly.cukes.length)
end
Test::Unit
Line numbers
Then bla bla # features/step_definitions/bla_steps.rb:16
Stack traces
When I send mass proposal email
Could not find link "Send proposal emails"
features/step_definitions/proposal_steps.rb:16
features/notification.feature:9
$ cucumber features/notifications.rb:9
Hooks
Before do
end
After do |scenario|
end
World do
end
World(MyModule)
World(HerModule)
support/hooks.rb or support/env.rb
Feature: Notification emails
Background:
Given the following proposals
| email | title |
| aslak.hellesoy@gmail.com | Cucumber |
| bryan@brynary.com | Webrat |
Scenario: Approved
Background: Rejected
Background
Tagged Hooks
Before('@im_special', '@me_too') do
@icecream = true
end
@me_too
Feature: Lorem
Scenario: Ipsum
Scenario: Dolor
Feature: Sit
@im_special
Scenario: Amet
Scenario: Consec
Feature: Take over the world
I want it all
@spanish @french @english
Scenario: Take over Europe
@spanish @english
Scenario: Take over America
@english
Scenario: Take over Australia
cucumber -t spanish doit.featurecucumber -t ~french doit.feature
Tagged Execution
What s
inside?
a.feature
b.feature
x_steps.rb
y_steps.rb
Your
CodeRSpec/Test::Unit/Shoulda
Not doing Rails?
Quality Code With Cucumber Presentation

Mais conteúdo relacionado

Mais procurados

Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles ServiceAraport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Servicestevemock
 
Powershell to the People #suguk
Powershell to the People #sugukPowershell to the People #suguk
Powershell to the People #sugukChris McKinley
 
Copycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBCopycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBbostonrb
 
Start developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsStart developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsMasakuni Kato
 
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...VMware Tanzu
 

Mais procurados (6)

Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles ServiceAraport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
 
Powershell to the People #suguk
Powershell to the People #sugukPowershell to the People #suguk
Powershell to the People #suguk
 
Advanced WordPress Tooling
Advanced WordPress ToolingAdvanced WordPress Tooling
Advanced WordPress Tooling
 
Copycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBCopycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRB
 
Start developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsStart developing Facebook apps in 13 steps
Start developing Facebook apps in 13 steps
 
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...
Spring Boot Omakase: A Fast-Paced “Chef’s Choice” Dive into Fun and Useful To...
 

Destaque

Don T Mock Yourself Out Presentation
Don T Mock Yourself Out PresentationDon T Mock Yourself Out Presentation
Don T Mock Yourself Out Presentationrailsconf
 
Online Omdømme Del1 Anfo April 2009
Online Omdømme Del1 Anfo April 2009Online Omdømme Del1 Anfo April 2009
Online Omdømme Del1 Anfo April 2009Metronet
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amfrailsconf
 
Rails Is From Mars Ruby Is From Venus Presentation 1
Rails Is From Mars  Ruby Is From Venus Presentation 1Rails Is From Mars  Ruby Is From Venus Presentation 1
Rails Is From Mars Ruby Is From Venus Presentation 1railsconf
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applicationsrailsconf
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosLindsay Holmwood
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructureLindsay Holmwood
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With CucumberSean Cribbs
 
Acceptance testing with Geb
Acceptance testing with GebAcceptance testing with Geb
Acceptance testing with GebRichard Paul
 

Destaque (10)

Don T Mock Yourself Out Presentation
Don T Mock Yourself Out PresentationDon T Mock Yourself Out Presentation
Don T Mock Yourself Out Presentation
 
Online Omdømme Del1 Anfo April 2009
Online Omdømme Del1 Anfo April 2009Online Omdømme Del1 Anfo April 2009
Online Omdømme Del1 Anfo April 2009
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Rails Is From Mars Ruby Is From Venus Presentation 1
Rails Is From Mars  Ruby Is From Venus Presentation 1Rails Is From Mars  Ruby Is From Venus Presentation 1
Rails Is From Mars Ruby Is From Venus Presentation 1
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applications
 
Pastorets 2.0
Pastorets 2.0Pastorets 2.0
Pastorets 2.0
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagios
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructure
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
 
Acceptance testing with Geb
Acceptance testing with GebAcceptance testing with Geb
Acceptance testing with Geb
 

Semelhante a Quality Code With Cucumber Presentation

Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...
Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...
Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...Aslak Hellesøy
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScriptJoost Elfering
 
Feature Flagging your Infrastructure for Fun and Profit
Feature Flagging your Infrastructure for Fun and ProfitFeature Flagging your Infrastructure for Fun and Profit
Feature Flagging your Infrastructure for Fun and ProfitDaniel Schauenberg
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"testflyjets
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuLucas Renan
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingPatrick Reagan
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedykrivachy
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...Akira Tsuruda
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichSmartLogic
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budgetDavid Lukac
 

Semelhante a Quality Code With Cucumber Presentation (18)

Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...
Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...
Executable Requirements with Behaviour-Driven Development and Cucumber - Euro...
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Cuke4Duke JavaZone 2009
Cuke4Duke JavaZone 2009Cuke4Duke JavaZone 2009
Cuke4Duke JavaZone 2009
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
 
Feature Flagging your Infrastructure for Fun and Profit
Feature Flagging your Infrastructure for Fun and ProfitFeature Flagging your Infrastructure for Fun and Profit
Feature Flagging your Infrastructure for Fun and Profit
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
Cucumber testing
Cucumber testingCucumber testing
Cucumber testing
 
Cucumber testing
Cucumber testingCucumber testing
Cucumber testing
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
Flask-RESTPlusで便利なREST API開発 | Productive RESTful API development with Flask-...
 
Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 

Mais de railsconf

Smacking Git Around Advanced Git Tricks
Smacking Git Around   Advanced Git TricksSmacking Git Around   Advanced Git Tricks
Smacking Git Around Advanced Git Tricksrailsconf
 
Running The Show Configuration Management With Chef Presentation
Running The Show  Configuration Management With Chef PresentationRunning The Show  Configuration Management With Chef Presentation
Running The Show Configuration Management With Chef Presentationrailsconf
 
Sd208 Ds%2 C0
Sd208 Ds%2 C0Sd208 Ds%2 C0
Sd208 Ds%2 C0railsconf
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentationrailsconf
 
J Ruby On Rails Presentation
J Ruby On Rails PresentationJ Ruby On Rails Presentation
J Ruby On Rails Presentationrailsconf
 
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
Gov 2 0  Transparency  Collaboration  And Participation In Practice PresentationGov 2 0  Transparency  Collaboration  And Participation In Practice Presentation
Gov 2 0 Transparency Collaboration And Participation In Practice Presentationrailsconf
 
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...railsconf
 
Building A Mini Google High Performance Computing In Ruby
Building A Mini Google  High Performance Computing In RubyBuilding A Mini Google  High Performance Computing In Ruby
Building A Mini Google High Performance Computing In Rubyrailsconf
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Railsrailsconf
 
The Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines PresentationThe Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines Presentationrailsconf
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...railsconf
 

Mais de railsconf (11)

Smacking Git Around Advanced Git Tricks
Smacking Git Around   Advanced Git TricksSmacking Git Around   Advanced Git Tricks
Smacking Git Around Advanced Git Tricks
 
Running The Show Configuration Management With Chef Presentation
Running The Show  Configuration Management With Chef PresentationRunning The Show  Configuration Management With Chef Presentation
Running The Show Configuration Management With Chef Presentation
 
Sd208 Ds%2 C0
Sd208 Ds%2 C0Sd208 Ds%2 C0
Sd208 Ds%2 C0
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
J Ruby On Rails Presentation
J Ruby On Rails PresentationJ Ruby On Rails Presentation
J Ruby On Rails Presentation
 
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
Gov 2 0  Transparency  Collaboration  And Participation In Practice PresentationGov 2 0  Transparency  Collaboration  And Participation In Practice Presentation
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
 
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
 
Building A Mini Google High Performance Computing In Ruby
Building A Mini Google  High Performance Computing In RubyBuilding A Mini Google  High Performance Computing In Ruby
Building A Mini Google High Performance Computing In Ruby
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Rails
 
The Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines PresentationThe Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines Presentation
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
 

Último

TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?Paolo Missier
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 

Último (20)

TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 

Quality Code With Cucumber Presentation

  • 1. Aslak Hellesøy - Chief Scientist http://cukes.info/ twitter.com/aslak_hellesoy aslak.hellesoy@gmail.com
  • 5. 85 committers 989 github followers 33000 gem downloads 30 related tools http://www.flickr.com/photos/twose/887903401/
  • 6. http://www.flickr.com/photos/purrr/126597849/ It s testing crack. One serious stab at using it and I'm hooked.
  • 7. features step_definitions support env.rb webrat_steps.rb paths.rb Installing Cucumber $ gem install cucumber webrat rspec-rails rspec $ script/generate cucumber
  • 8. ENV["RAILS_ENV"] ||= "test" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' require 'cucumber/formatter/unicode' Cucumber::Rails.use_transactional_fixtures Cucumber::Rails.bypass_rescue # Plus some more setup stuff..... env.rb
  • 9. webrat_steps.rb Given /^I am on (.+)$/ do |page_name| visit path_to(page_name) end When /^I press "([^"]*)"$/ do |button| click_button(button) end Then /^I should see "([^"]*)"$/ do |text| response.should contain(text) end
  • 10. module NavigationHelpers # When /^I go to (.+)$/ do |page_name| def path_to(page_name) case page_name when /the homepage/ '/' when /^(.*)'s profile page$/i user_profile_path(User.find_by_login($1)) else raise "Can't find mapping for "#{page_name}"" end end end World(NavigationHelpers) paths.rb
  • 12.
  • 13. Proposal notification In order to reduce time spent on emailing Administrators should be able to mail proposal status to all owners
  • 15. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """ Our First Feature features/proposal_notification.feature
  • 17. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """ 1 scenario (1 undefined) 4 steps (4 undefined)
  • 18. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """ 1 scenario (1 undefined) 4 steps (4 undefined)
  • 19. You can implement step definitions for undefined steps with these snippets: Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do pending end Given /^the Cucumber proposal is approved$/ do pending end When /^I send proposal emails$/ do pending end Then /^aslak.hellesoy@gmail.com should get email$/ do |string| pending end
  • 20. Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do pending end Given /^the Cucumber proposal is approved$/ do pending end When /^I send proposal emails$/ do pending end Then /^aslak.hellesoy@gmail.com should get email$/ do |string| pending end Step Definitions features/step_definitions/proposal_steps.rb
  • 22. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber TODO (Cucumber::Pending) features/step_definitions/proposal_steps.rb:2 features/proposal_notification.feature:7 And the Cucumber proposal is approved When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 23. Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do Proposal.create!({ :email => 'aslak.hellesoy@gmail.com', :title => 'Cucumber' }) end Do what Regexp says features/step_definitions/proposal_steps.rb
  • 24. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber uninitialized constant Proposal (NameError) features/step_definitions/proposal_steps.rb:2 features/proposal_notification.feature:7 And the Cucumber proposal is approved When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 25. $ script/generate rspec_scaffold proposal email:string title:string approved:boolean $ rake db:migrate db:test:clone $ cucumber features --no-source Make it Pass
  • 26. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved TODO (Cucumber::Pending) features/step_definitions/proposal_steps.rb:9 features/proposal_notification.feature:8 When I send proposal emails Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 27. Given /^the Cucumber proposal is approved$/ do proposal = Proposal.find_by_title('Cucumber') proposal.approved = true proposal.save! end Implement Intention features/step_definitions/proposal_steps.rb
  • 28. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send proposal emails TODO (Cucumber::Pending) features/step_definitions/proposal_steps.rb:15 features/proposal_notification.feature:9 Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 29. When /^I send mass proposal email$/ do visit(’admin’) click_button("Send proposal emails") end Webrat
  • 30. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send mass proposal email No route matches "/admin" with {:method=>:get} features/step_definitions/proposal_steps.rb:16 features/proposal_notification.feature:9 Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 31.
  • 32. Add the Controller class AdminController < ApplicationController def index end end
  • 33. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send mass proposal email Could not find link "Send proposal emails" features/step_definitions/proposal_steps.rb:16 features/proposal_notification.feature:9 Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 34. Add the link <%= link_to("Send proposal emails", :action => 'mass_email') %>
  • 35. And #mass_email class AdminController < ApplicationController def index end def mass_email end end
  • 36. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send mass proposal email Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 37. Email-Spec Then /^... should get email$/ do |body| open_email('aslak.hellesoy@gmail.com') current_email.body.should == body end
  • 38. class AdminController < ApplicationController def index end def mass_email approved = Proposal.find_all_by_approved(true) approved.each do |proposal| AdminMailer.deliver_notification_email(proposal) end end end Controller
  • 39. class AdminMailer < ActionMailer::Base def notification_email(proposal) recipients proposal.email from "confreg@oreilly.com" subject "Your Railsconf proposal" body :proposal => proposal end end Mailer
  • 40. Hi <%= @proposal.email %> Congratulations, <%= @proposal.title %> was accepted. See you at RailsConf! Mailer template
  • 41. Feature: Proposal notification In order to reduce time spent on emailing Administrators should be able to mail all proposals owners depending on status Scenario: Email accepted proposal Given aslak.hellesoy@gmail.com proposed Cucumber And the Cucumber proposal is approved When I send mass proposal email Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """
  • 43. Steps & Step Definitions Given aslak.hellesoy@gmail.com proposed Cucumber Given /^aslak.hellesoy@gmail.com proposed Cucumber$/ do end Step == Method invocation Step Definition == Method defnition
  • 44. Regexp group arguments Given aslak.hellesoy@gmail.com proposed Cucumber Given /^(.+) proposed (.+)$/ do |email, proposal_name| end Given aslak.hellesoy@gmail.com proposed Cucumber $CUCUMBER_COLORS
  • 45. Quoted arguments Given I have "22" cukes in my belly Given /^I have "([^"]*)" cukes in my belly$/ do |n| end Given I have "2" cukes in my belly
  • 46. Multiline args (String) Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumber was accepted. See you at RailsConf! """ Then /^(.+) should get email$/ do |email, body| end
  • 47. Multiline args (Tables) Given the following proposals | email | title | | aslak.hellesoy@gmail.com | Cucumber | | bryan@brynary.com | Webrat | Given /the following proposals$/ do |proposals| Proposal.create!(proposals.hashes) end
  • 48. Scenario Outline: Email accepted proposals Given the following proposals | email | title | | aslak.hellesoy@gmail.com | Cucumber | | bryan@brynary.com | Webrat | And the <proposal> proposal is approved When I send proposal emails Then <email> should <what> Examples: | proposal | email | what | | Cucumber | aslak.hellesoy@gmail.com | get email | | Cucumber | bryan@brynary.com | not get email | | Webrat | bryan@brynary.com | get email | Scenario Outline
  • 49. OH HAI: STUFFING MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ WEN I EAT 2 CUCUMBRZ DEN I HAZ 2 CUCUMBERZ IN MAH BELLY AN IN TEH END 1 CUCUMBRZ KTHXBAI $ cucumber -l en-lol stuffing.feature
  • 51. Then /^I should have "(d+)" cukes my belly$/ do |cukes| @belly.cukes.length.should == cukes.to_i end RSpec Then /^I should have "(d+)" cukes my belly$/ do |cukes| @belly.should have(cukes.to_i).cukes end Kosher RSpec Then /^I should have "(d+)" cukes my belly$/ do |cukes| assert_equal(@cukes.to_i, @belly.cukes.length) end Test::Unit
  • 52. Line numbers Then bla bla # features/step_definitions/bla_steps.rb:16
  • 53. Stack traces When I send mass proposal email Could not find link "Send proposal emails" features/step_definitions/proposal_steps.rb:16 features/notification.feature:9 $ cucumber features/notifications.rb:9
  • 54. Hooks Before do end After do |scenario| end World do end World(MyModule) World(HerModule) support/hooks.rb or support/env.rb
  • 55. Feature: Notification emails Background: Given the following proposals | email | title | | aslak.hellesoy@gmail.com | Cucumber | | bryan@brynary.com | Webrat | Scenario: Approved Background: Rejected Background
  • 56. Tagged Hooks Before('@im_special', '@me_too') do @icecream = true end @me_too Feature: Lorem Scenario: Ipsum Scenario: Dolor Feature: Sit @im_special Scenario: Amet Scenario: Consec
  • 57. Feature: Take over the world I want it all @spanish @french @english Scenario: Take over Europe @spanish @english Scenario: Take over America @english Scenario: Take over Australia cucumber -t spanish doit.featurecucumber -t ~french doit.feature Tagged Execution