Presentation I gave at the October Sydney RORO meetup on Cucumber, the new Ruby library for writing executable story-based tests; and FactoryGirl, a library for creating valid AR models for tests/specs/stories.
Most examples come from the Webjam codebase which can be found on github:
http://github.com/webjam/webjam/
Video of the preso can be found here:
http://www.viddler.com/explore/snapperwolf/videos/7
Faces preso page here:
http://faces.rubyonrails.com.au/groups/sydney/meetings/2008-10-08/presos/2
25. Story: Viewing the home page
As a visitor
I want to visit the home page
So that I can see all the cool stuff
Scenario: not logged in
Given I am not logged in
When I view the home page
Then I see the page
/features/home.feature
36. Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
And the result class should be Fixnum
| input_1 | input_2 | button | output | class |
| 20 | 30 | add | 50 | Fixnum |
| 2 | 5 | add | 7 | Fixnum |
| 0 | 40 | add | 40 | Fixnum |
37. Before do
@calc = Calculator.new
end
After do
end
Given quot;I have entered $n into the calculatorquot; do |n|
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the result should be (.*) on the screen/ do |result|
@result.should == result.to_f
end
Then /the result class should be (w*)/ do |class_name|
@result.class.name.should == class_name
end
38. Before do
@calc = Calculator.new
end
After do
end
Given quot;I have entered $n into the calculatorquot; do |n|
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the result should be (.*) on the screen/ do |result|
@result.should == result.to_f
end
Then /the result class should be (w*)/ do |class_name|
@result.class.name.should == class_name
end
39. Before do
@calc = Calculator.new
end
After do
end
Given quot;I have entered $n into the calculatorquot; do |n|
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the result should be (.*) on the screen/ do |result|
@result.should == result.to_f
end
Then /the result class should be (w*)/ do |class_name|
@result.class.name.should == class_name
end
40. Before do
@calc = Calculator.new
end
After do
end
Given quot;I have entered $n into the calculatorquot; do |n|
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the result should be (.*) on the screen/ do |result|
@result.should == result.to_f
end
Then /the result class should be (w*)/ do |class_name|
@result.class.name.should == class_name
end
41. Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
And the result class should be Fixnum
| input_1 | input_2 | button | output | class |
| 20 | 30 | add | 50 | Fixnum |
| 2 | 5 | add | 7 | Fixnum |
| 0 | 40 | add | 40 | Fixnum |
42. Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
And the result class should be Fixnum
| input_1 | input_2 | button | output | class |
| 20 | 30 | add | 50 | Fixnum |
| 2 | 5 | add | 7 | Fixnum |
| 0 | 40 | add | 40 | Fixnum |
56. Factory.define :presentation, :class => Jam do |p|
p.title 'Preso title'
p.description 'Preso description'
p.number {Factory.next(:jam_number)}
p.users {|u| [u.association(:user)]}
p.association :event
end
57. When quot;I view an event presentation pagequot; do
@event = Factory.create(:past_event)
@presentation = Factory.create(:presentation,
:event => @event)
get event_presentation_path(@event, @presentation)
end