cucumbers & factory girls

60
CUCUMBERS! AND FACTORY GIRLS

Upload: tim-lucas

Post on 28-Jan-2015

126 views

Category:

Technology


0 download

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/2

TRANSCRIPT

Page 1: Cucumbers & Factory Girls

CUCUMBERS! AND FACTORY GIRLS

Page 2: Cucumbers & Factory Girls

CUCUMBER

Page 3: Cucumbers & Factory Girls

STORIES

Page 4: Cucumbers & Factory Girls

210 SCENARIOS

Page 5: Cucumbers & Factory Girls

BIG BULLSHIT NUMBERS

Page 6: Cucumbers & Factory Girls

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

RSPEC STORIES

Page 8: Cucumbers & Factory Girls

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

OLD SCHOOL

Page 10: Cucumbers & Factory Girls

PHOTO BY:flickr.com/people/rumberodesign

GOOD OLD SCHOOL

Page 11: Cucumbers & Factory Girls

BAD OLD SCHOOL

Page 12: Cucumbers & Factory Girls

BENEFITS OF CUCUMBER?

Page 13: Cucumbers & Factory Girls
Page 14: Cucumbers & Factory Girls

HIGH WATER CONTENT

Page 15: Cucumbers & Factory Girls

SKIN IS RICH IN FIBER

Page 16: Cucumbers & Factory Girls

REGULATE BLOOD PRESSURE

Page 17: Cucumbers & Factory Girls

RUBY + CUCUMBERS?

Page 18: Cucumbers & Factory Girls

JAPAN + CUCUMBERS?

Page 21: Cucumbers & Factory Girls

DEMO: WEBJAM

http://github.com/webjam/webjam - rake features

Page 22: Cucumbers & Factory Girls
Page 23: Cucumbers & Factory Girls

/features

Page 24: Cucumbers & Factory Girls

/features/*.feature

Page 25: Cucumbers & Factory Girls

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

/features/steps

Page 27: Cucumbers & Factory Girls

/features/steps/*_steps.rb

Page 28: Cucumbers & Factory Girls

When "I view the home page" do get home_pathend

/features/home_steps.rb

Page 29: Cucumbers & Factory Girls

Then "I see the page" do response.code.should == "200"end

/features/response_steps.rb

Page 30: Cucumbers & Factory Girls

FEATURES

Page 31: Cucumbers & Factory Girls

RUBY

Page 32: Cucumbers & Factory Girls

RAILS INTEGRATION

Page 33: Cucumbers & Factory Girls

TREETOP

Page 34: Cucumbers & Factory Girls

STORY RUNNER COMPATIBLE

Page 35: Cucumbers & Factory Girls

FIT TABLES

Page 36: Cucumbers & Factory Girls

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

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

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

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

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

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

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

GETTING STARTED WITH RAILS

Page 44: Cucumbers & Factory Girls

INSTALL PLUGIN

Page 45: Cucumbers & Factory Girls

./script/generate cucumber

Page 46: Cucumbers & Factory Girls

FACTORY GIRL

Page 47: Cucumbers & Factory Girls
Page 48: Cucumbers & Factory Girls
Page 49: Cucumbers & Factory Girls
Page 50: Cucumbers & Factory Girls

INSTANTIATING MODELS

Page 51: Cucumbers & Factory Girls

FIXTURELESS

Page 52: Cucumbers & Factory Girls

SPECS and/or STORIES

Page 53: Cucumbers & Factory Girls

LACHIE (LACHIE COX)

HORNSBY

Page 54: Cucumbers & Factory Girls

NOTAHAT (PETE YANDELL)

MACHINIST

Page 55: Cucumbers & Factory Girls

AGAIN, WEBJAMhttp://github.com/webjam/webjam/tree/master/spec/factories.rb

Page 56: Cucumbers & Factory Girls

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

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

ASSOCIATIONS

Page 59: Cucumbers & Factory Girls

SEQUENCES

Page 60: Cucumbers & Factory Girls

TIM LUCASTWITTER.COM/TOOLMANTIM

TOOLMANTIM.COM