cucumbers & factory girls
DESCRIPTION
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/2TRANSCRIPT
![Page 1: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/1.jpg)
CUCUMBERS! AND FACTORY GIRLS
![Page 2: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/2.jpg)
CUCUMBER
![Page 3: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/3.jpg)
STORIES
![Page 4: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/4.jpg)
210 SCENARIOS
![Page 5: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/5.jpg)
BIG BULLSHIT NUMBERS
![Page 6: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/6.jpg)
In order to show the world how cool they areA userShould be able to edit and update their personal details
![Page 7: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/7.jpg)
RSPEC STORIES
![Page 8: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/8.jpg)
As a userI want to edit and update my personal detailsSo that I can show the world how cool I am
![Page 9: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/9.jpg)
OLD SCHOOL
![Page 10: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/10.jpg)
PHOTO BY:flickr.com/people/rumberodesign
GOOD OLD SCHOOL
![Page 11: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/11.jpg)
BAD OLD SCHOOL
![Page 12: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/12.jpg)
BENEFITS OF CUCUMBER?
![Page 13: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/13.jpg)
![Page 14: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/14.jpg)
HIGH WATER CONTENT
![Page 15: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/15.jpg)
SKIN IS RICH IN FIBER
![Page 16: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/16.jpg)
REGULATE BLOOD PRESSURE
![Page 17: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/17.jpg)
RUBY + CUCUMBERS?
![Page 18: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/18.jpg)
JAPAN + CUCUMBERS?
![Page 19: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/19.jpg)
http://www.youtube.com/watch?v=U3OxKdDxkpg
http://www.youtube.com/watch?v=fBsyBjQuX6E
![Page 20: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/20.jpg)
http://github.com/aslakhellesoy/cucumber/
![Page 21: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/21.jpg)
DEMO: WEBJAM
http://github.com/webjam/webjam - rake features
![Page 22: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/22.jpg)
![Page 23: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/23.jpg)
/features
![Page 24: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/24.jpg)
/features/*.feature
![Page 25: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/25.jpg)
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
![Page 26: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/26.jpg)
/features/steps
![Page 27: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/27.jpg)
/features/steps/*_steps.rb
![Page 28: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/28.jpg)
When "I view the home page" do get home_pathend
/features/home_steps.rb
![Page 29: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/29.jpg)
Then "I see the page" do response.code.should == "200"end
/features/response_steps.rb
![Page 30: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/30.jpg)
FEATURES
![Page 31: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/31.jpg)
RUBY
![Page 32: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/32.jpg)
RAILS INTEGRATION
![Page 33: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/33.jpg)
TREETOP
![Page 34: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/34.jpg)
STORY RUNNER COMPATIBLE
![Page 35: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/35.jpg)
FIT TABLES
![Page 36: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/36.jpg)
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 |
![Page 37: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/37.jpg)
Before do @calc = Calculator.newend After doend Given "I have entered $n into the calculator" do |n| @calc.push n.to_iend When /I press (\w+)/ do |op| @result = @calc.send opend Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_fend Then /the result class should be (\w*)/ do |class_name| @result.class.name.should == class_nameend
![Page 38: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/38.jpg)
Before do @calc = Calculator.newend After doend Given "I have entered $n into the calculator" do |n| @calc.push n.to_iend When /I press (\w+)/ do |op| @result = @calc.send opend Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_fend Then /the result class should be (\w*)/ do |class_name| @result.class.name.should == class_nameend
![Page 39: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/39.jpg)
Before do @calc = Calculator.newend After doend Given "I have entered $n into the calculator" do |n| @calc.push n.to_iend When /I press (\w+)/ do |op| @result = @calc.send opend Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_fend Then /the result class should be (\w*)/ do |class_name| @result.class.name.should == class_nameend
![Page 40: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/40.jpg)
Before do @calc = Calculator.newend After doend Given "I have entered $n into the calculator" do |n| @calc.push n.to_iend When /I press (\w+)/ do |op| @result = @calc.send opend Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_fend Then /the result class should be (\w*)/ do |class_name| @result.class.name.should == class_nameend
![Page 41: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/41.jpg)
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 |
![Page 42: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/42.jpg)
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 |
![Page 43: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/43.jpg)
GETTING STARTED WITH RAILS
![Page 44: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/44.jpg)
INSTALL PLUGIN
![Page 45: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/45.jpg)
./script/generate cucumber
![Page 46: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/46.jpg)
FACTORY GIRL
![Page 47: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/47.jpg)
![Page 48: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/48.jpg)
![Page 49: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/49.jpg)
![Page 50: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/50.jpg)
INSTANTIATING MODELS
![Page 51: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/51.jpg)
FIXTURELESS
![Page 52: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/52.jpg)
SPECS and/or STORIES
![Page 53: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/53.jpg)
LACHIE (LACHIE COX)
HORNSBY
![Page 54: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/54.jpg)
NOTAHAT (PETE YANDELL)
MACHINIST
![Page 55: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/55.jpg)
AGAIN, WEBJAMhttp://github.com/webjam/webjam/tree/master/spec/factories.rb
![Page 56: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/56.jpg)
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 :eventend
![Page 57: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/57.jpg)
When "I view an event presentation page" do @event = Factory.create(:past_event) @presentation = Factory.create(:presentation, :event => @event) get event_presentation_path(@event, @presentation)end
![Page 58: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/58.jpg)
ASSOCIATIONS
![Page 59: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/59.jpg)
SEQUENCES
![Page 60: Cucumbers & Factory Girls](https://reader033.vdocuments.net/reader033/viewer/2022051014/54c891494a795957258b4572/html5/thumbnails/60.jpg)
TIM LUCASTWITTER.COM/TOOLMANTIM
TOOLMANTIM.COM