CUCUMBERS! AND FACTORY GIRLS
CUCUMBER
STORIES
210 SCENARIOS
BIG BULLSHIT NUMBERS
In order to show the world how cool they are
A user
Should be able to edit and update their personal details
RSPEC STORIES
As a user
I want to edit and update my personal details
So that I can show the world how cool I am
OLD SCHOOL
GOOD OLD SCHOOL




                                     PHOTO BY:
                  flickr.com/people/rumberodesign
BAD OLD SCHOOL
BENEFITS OF CUCUMBER?
HIGH WATER CONTENT
SKIN IS RICH IN FIBER
REGULATE BLOOD PRESSURE
RUBY + CUCUMBERS?
JAPAN + CUCUMBERS?
http://www.youtube.com/watch?v=fBsyBjQuX6E




http://www.youtube.com/watch?v=U3OxKdDxkpg
http://github.com/aslakhellesoy/cucumber/
DEMO: WEBJAM
http://github.com/webjam/webjam - rake features
/features
/features/*.feature
Story: Viewing the home page

  As a visitor
  I want to visit the home page
  So that I can see all the cool stuff

  Sce...
/features/steps
/features/steps/*_steps.rb
When quot;I view the home pagequot; do
   get home_path
 end




/features/home_steps.rb
Then quot;I see the pagequot; do
   response.code.should == quot;200quot;
 end




/features/response_steps.rb
FEATURES
RUBY
RAILS INTEGRATION
TREETOP
STORY RUNNER COMPATIBLE
FIT TABLES
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scena...
Before do
  @calc = Calculator.new
end

After do
end

Given quot;I have entered $n into the calculatorquot; do |n|
  @calc...
Before do
  @calc = Calculator.new
end

After do
end

Given quot;I have entered $n into the calculatorquot; do |n|
  @calc...
Before do
  @calc = Calculator.new
end

After do
end

Given quot;I have entered $n into the calculatorquot; do |n|
  @calc...
Before do
  @calc = Calculator.new
end

After do
end

Given quot;I have entered $n into the calculatorquot; do |n|
  @calc...
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scena...
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scena...
GETTING STARTED
  WITH RAILS
INSTALL PLUGIN
./script/generate cucumber
FACTORY GIRL
INSTANTIATING MODELS
FIXTURELESS
SPECS and/or STORIES
HORNSBY



    LACHIE (LACHIE COX)
MACHINIST



     NOTAHAT (PETE YANDELL)
AGAIN, WEBJAM
http://github.com/webjam/webjam/tree/master/spec/factories.rb
Factory.define :presentation, :class => Jam do |p|
  p.title 'Preso title'
  p.description 'Preso description'
  p.number ...
When quot;I view an event presentation pagequot; do
  @event = Factory.create(:past_event)
  @presentation = Factory.creat...
ASSOCIATIONS
SEQUENCES
TIM LUCAS
TWITTER.COM/TOOLMANTIM
TOOLMANTIM.COM
Cucumbers & Factory Girls
Cucumbers & Factory Girls
Cucumbers & Factory Girls
Cucumbers & Factory Girls
Cucumbers & Factory Girls
Upcoming SlideShare
Loading in …5
×

Cucumbers & Factory Girls

13,536 views

Published on

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

Published in: Technology
2 Comments
19 Likes
Statistics
Notes
No Downloads
Views
Total views
13,536
On SlideShare
0
From Embeds
0
Number of Embeds
55
Actions
Shares
0
Downloads
222
Comments
2
Likes
19
Embeds 0
No embeds

No notes for slide

Cucumbers & Factory Girls

  1. 1. CUCUMBERS! AND FACTORY GIRLS
  2. 2. CUCUMBER
  3. 3. STORIES
  4. 4. 210 SCENARIOS
  5. 5. BIG BULLSHIT NUMBERS
  6. 6. In order to show the world how cool they are A user Should be able to edit and update their personal details
  7. 7. RSPEC STORIES
  8. 8. As a user I want to edit and update my personal details So that I can show the world how cool I am
  9. 9. OLD SCHOOL
  10. 10. GOOD OLD SCHOOL PHOTO BY: flickr.com/people/rumberodesign
  11. 11. BAD OLD SCHOOL
  12. 12. BENEFITS OF CUCUMBER?
  13. 13. HIGH WATER CONTENT
  14. 14. SKIN IS RICH IN FIBER
  15. 15. REGULATE BLOOD PRESSURE
  16. 16. RUBY + CUCUMBERS?
  17. 17. JAPAN + CUCUMBERS?
  18. 18. http://www.youtube.com/watch?v=fBsyBjQuX6E http://www.youtube.com/watch?v=U3OxKdDxkpg
  19. 19. http://github.com/aslakhellesoy/cucumber/
  20. 20. DEMO: WEBJAM http://github.com/webjam/webjam - rake features
  21. 21. /features
  22. 22. /features/*.feature
  23. 23. 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
  24. 24. /features/steps
  25. 25. /features/steps/*_steps.rb
  26. 26. When quot;I view the home pagequot; do get home_path end /features/home_steps.rb
  27. 27. Then quot;I see the pagequot; do response.code.should == quot;200quot; end /features/response_steps.rb
  28. 28. FEATURES
  29. 29. RUBY
  30. 30. RAILS INTEGRATION
  31. 31. TREETOP
  32. 32. STORY RUNNER COMPATIBLE
  33. 33. FIT TABLES
  34. 34. 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 |
  35. 35. 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
  36. 36. 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
  37. 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. 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. 39. 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 |
  40. 40. 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 |
  41. 41. GETTING STARTED WITH RAILS
  42. 42. INSTALL PLUGIN
  43. 43. ./script/generate cucumber
  44. 44. FACTORY GIRL
  45. 45. INSTANTIATING MODELS
  46. 46. FIXTURELESS
  47. 47. SPECS and/or STORIES
  48. 48. HORNSBY LACHIE (LACHIE COX)
  49. 49. MACHINIST NOTAHAT (PETE YANDELL)
  50. 50. AGAIN, WEBJAM http://github.com/webjam/webjam/tree/master/spec/factories.rb
  51. 51. 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
  52. 52. 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
  53. 53. ASSOCIATIONS
  54. 54. SEQUENCES
  55. 55. TIM LUCAS TWITTER.COM/TOOLMANTIM TOOLMANTIM.COM

×