integration testing in ruby with rspec’s story automation...
TRANSCRIPT
![Page 1: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/1.jpg)
Integration Testingin Ruby
withRSpec’s Story Automation
Framework
David Chelimskyarticulatedman.com
![Page 2: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/2.jpg)
Behaviour-Driven Development
![Page 3: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/3.jpg)
BDD
Writing software that matters- Dan North
![Page 4: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/4.jpg)
BDD
• Dan North/Aslak Hellesøy 2004
• Improve communication about Test Driven Development
• JBehave
![Page 5: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/5.jpg)
BDD• Second generation “full stack” Agile
methodology rooted in:
• Extreme Programming
• Acceptance Test Driven Planning
• Test Driven Development
![Page 6: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/6.jpg)
RSpec
![Page 7: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/7.jpg)
RSpec
• Behaviour Driven Development Framework
• Story Framework
• Acceptance Test Driven Planning
• Example Framework
• Test Driven Development
![Page 8: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/8.jpg)
RSpec Origins
• Inspired by a blog post by Dave Astels
• Authored by Steven Baker
• Summer ‘05
• Maintained by me
• Since Summer ‘06
http://daveastels.com/2005/07/05/a-new-look-at-test-driven-development/
![Page 9: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/9.jpg)
BDD Process
![Page 10: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/10.jpg)
Process
• Inject features discovered through analysis
• Feature Injection - Chris Matts
• Extract stories from features
• Focus on outputs
• Break stories down into scenarios
• Acceptance Criteria
![Page 11: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/11.jpg)
Feature Injection
![Page 12: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/12.jpg)
Popping the “Why?” Stack
![Page 13: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/13.jpg)
I want people to be able to register
![Page 14: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/14.jpg)
Why?
![Page 15: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/15.jpg)
I want to know how many people registered
![Page 16: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/16.jpg)
Why?
![Page 17: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/17.jpg)
So I can measure progress towards registration goals
![Page 18: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/18.jpg)
Why?
![Page 19: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/19.jpg)
This is getting really, really annoying
![Page 20: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/20.jpg)
I know ...
![Page 21: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/21.jpg)
Why?
![Page 22: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/22.jpg)
Why do you want to measure progress
towards registration goals?
![Page 23: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/23.jpg)
SO I CAN MANAGE
COST
![Page 24: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/24.jpg)
• If you keep asking “why?”, you’ll eventually land on one of:
• Generate/protect revenue
• Reduce/manage cost
• When you do, the answer to the previous “why?” is often a feature waiting to be discovered.
Popping the “Why?” Stack
![Page 25: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/25.jpg)
User Stories
• High level analysis and planning tool
• “Token for a conversation”
![Page 26: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/26.jpg)
BDD User Stories
• Add Scenarios that serve as Acceptance Criteria
![Page 27: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/27.jpg)
So what does this all have to do with
Integration Testing?
![Page 28: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/28.jpg)
Integration Testing
• Make sure the component parts play nice together
![Page 29: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/29.jpg)
Automated User Stories/Scenarios
• Document the expected behaviour of the system
• Verify that behaviour by executing a thin vertical slice of the system
![Page 30: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/30.jpg)
Conference Organizer(Example Application)
![Page 31: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/31.jpg)
Example Story
![Page 32: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/32.jpg)
Example Story
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 33: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/33.jpg)
Title
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 34: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/34.jpg)
Narrative
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 35: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/35.jpg)
Scenarios
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 36: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/36.jpg)
Narrative Format“The Connextra Format”
![Page 37: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/37.jpg)
As a Role
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 38: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/38.jpg)
I want Action
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 39: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/39.jpg)
So that Goal
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 40: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/40.jpg)
Narrative Format
• Completely arbitrary, but ...
• Look for a format that
• Identifies the goal
• Identifies the user/persona
• Identifies the action
![Page 41: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/41.jpg)
Alternate Format
Story: measure progress towards registration goals In order to measure progress towards registration goals As a conference organizer I want to see a report of registrations
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 42: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/42.jpg)
Scenario Format
![Page 43: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/43.jpg)
Given | When | ThenThe other GWT
![Page 44: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/44.jpg)
Given | When | Then
• A simple way of saying:
• Pre-conditions, Event, Post-conditions
• Context, Action, Outcome
• Build, Operate, Check
• Uncle Bob Martin
![Page 45: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/45.jpg)
Given | When | Then
• Words that can be understood equally well by:
• stakeholders
• business analysts
• developers
• testers
![Page 46: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/46.jpg)
Given
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 47: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/47.jpg)
When
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 48: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/48.jpg)
Then
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 49: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/49.jpg)
Automation
![Page 50: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/50.jpg)
RubyStory "measure progress towards registration goals",%( As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals), :type => RailsStory, :steps_for => :registrations do Scenario "one registration shows as 1%" do Given "a goal of 200 registrations" When "1 attendee registers" Then "the goal should be 1% achieved" end Scenario "one registration less than the goal shows as 99%" do Given "a goal of 200 registrations" When "199 attendees register" Then "the goal should be 99% achieved" endend
![Page 51: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/51.jpg)
Plain TextStory: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 52: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/52.jpg)
Plain Text
with_steps_for :registrations do run "#{File.dirname(__FILE__)}/measure_progress.story", :type => RailsStoryend
![Page 53: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/53.jpg)
Step Definitions
![Page 54: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/54.jpg)
Direct Model Access
![Page 55: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/55.jpg)
Given
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 56: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/56.jpg)
Given
steps_for :registrations do Given "a goal of $goal registrations" do |goal| @conference = Conference.create!( :name => "BDD", :goal => goal ) endend
![Page 57: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/57.jpg)
Given
steps_for :registrations do Given "a goal of $goal registrations" do |goal| @conference = Conference.create!( :name => "BDD", :goal => goal ) endend
![Page 58: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/58.jpg)
When
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 59: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/59.jpg)
When
steps_for :registrations do ... When /(\d+) attendees? registers?/ do |count| (1..(count.to_i)).each do |n| Registration.create!( :name => "Name #{n}", :email => "email#{n}@site.com", :conference => @conference ) end endend
![Page 60: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/60.jpg)
When
steps_for :registrations do ... When /(\d+) attendees? registers?/ do |count,_,_| (1..(count.to_i)).each do |n| Registration.create!( :name => "Name #{n}", :email => "email#{n}@site.com", :conference => @conference ) end endend
![Page 61: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/61.jpg)
Then
Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals
Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved
![Page 62: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/62.jpg)
Then
steps_for :registrations do ... Then "the goal should be $percentage% achieved" do |percentage| @conference.percentage_of_goal.should == percentage.to_i endend
![Page 63: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/63.jpg)
Then
steps_for :registrations do ... Then "the goal should be $percentage% achieved" do |percentage| @conference.percentage_of_goal.should == percentage.to_i endend
![Page 64: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/64.jpg)
Direct Model Access
• Pros
• More flexible
• Less brittle
• Cons
• Less thorough
• No views/controllers
![Page 65: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/65.jpg)
(Almost) Full Stackusing
Rails Integration Testand
Webrat
![Page 66: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/66.jpg)
Rails Integration Test
• Simulate HTTP requests
• Goes through routing (unlike Rails functional tests)
• Simulate multiple sessions
![Page 67: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/67.jpg)
RailsStory
• Wraps Rails Integration Test
• Access to everything you get from Rails
• Access to everything you get from RSpec
![Page 68: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/68.jpg)
Given
steps_for :registrations_through_rails_stack do Given "a goal of $goal registrations" do |goal| get "/conferences/new" response.should have_tag( "form[action=?]", conferences_path) do with_tag("input#conference_name") with_tag("input#conference_goal") end @conference_name = "BDD #{Time.new.to_i}" post conferences_path, :conference => { :name => @conference_name, :goal => goal } endend
![Page 69: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/69.jpg)
Duplication
steps_for :registrations_through_rails_stack do Given "a goal of $goal registrations" do |goal| get "/conferences/new" response.should have_tag( "form[action=?]", conferences_path) do with_tag("input#conference_name") with_tag("input#conference_goal") end @conference_name = "BDD #{Time.new.to_i}" post conferences_path, :conference => { :name => @conference_name, :goal => goal } endend
![Page 70: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/70.jpg)
Webrat
• Ruby Gem maintained by Bryan Helmkamp
• http://github.com/brynary/webrat
• stores DOM in memory
• manipulates DOM
• builds POST from DOM
• logically binding the form to the POST
![Page 71: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/71.jpg)
Given (with Webrat)
steps_for :registrations_through_rails_stack do Given "a goal of $goal registrations" do |goal| @conference_name = "BDD #{Time.new.to_i}" visits new_conference_path fills_in "Name", :with => @conference_name fills_in "Goal", :with => goal clicks_button "Goal" endend
![Page 72: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/72.jpg)
When
steps_for :registrations_through_rails_stack do ... When /(\d+) attendees? registers?/ do |count| (1..(count.to_i)).each do |n| visits new_registration_path fills_in "Name", :with => "Name #{n}" fills_in "E-Mail", :with => "email#{n}@site.com" selects @conference_name clicks_button end endend
![Page 73: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/73.jpg)
Then
steps_for :registrations_through_rails_stack do ... Then "the goal should be $percentage% achieved" do |percentage| @conference = Conference.find_by_name(@conference_name) visits conference_path(@conference) response.should have_text(/#{percentage}%/) endend
![Page 74: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/74.jpg)
Full Stack (sans browser)
• Pros
• Full stack
• High level of coverage
• Confidence
![Page 75: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/75.jpg)
Full Stack (sans browser)
• Cons
• Full Stack
• Subject to changes from larger area
• Requires known html elements/structure
• Not too bad if you follow conventions
• Webrat helps too
![Page 76: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/76.jpg)
Full Stackusing
Selenium-RC
![Page 77: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/77.jpg)
Given
steps_for :registrations_through_browser do Given "a goal of $goal registrations" do |goal| $browser.open "http://localhost:3000/conferences/new" @conference_name = "BDD #{Time.new.to_i}" $browser.type "conference_name", @conference_name $browser.type "conference_goal", goal $browser.submit "new_conference" $browser.wait_for_page_to_load(5000) @conference_url = $browser.get_location endend
![Page 78: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/78.jpg)
steps_for :registrations_through_browser do ... When /(\d+) attendees? registers?/ do |count| (1..(count.to_i)).each do |n| $browser.open "http://localhost:3000/registrations/new" $browser.type "css=#registration_name", "Name #{n}" $browser.type "css=#registration_email", "email#{n}@site.com" $browser.select "css=#registration_conference_id", @conference_name $browser.submit "css=#new_registration" end endend
When
![Page 79: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/79.jpg)
Then
steps_for :registrations_through_browser do ... Then "the goal should be $percentage% achieved" do |percentage| $browser.open @conference_url $browser.get_text("css=#percentage_of_goal"). should =~ /#{percentage}%/ endend
![Page 80: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/80.jpg)
Full Stack (with browser)
• Pros
• Test javascript/ajax
• Test some aspects of HTML too
• You can watch it!
• High impact for customers
![Page 81: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/81.jpg)
Full Stack (with browser)
• Cons
• Brittle
• Like in-memory, coupled to entire stack
• Possibly even more subject to UI changes
• S L O W
![Page 82: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/82.jpg)
Full Stack (with browser)
• Recommendation
• Use in-memory first
• Use in-browser when
• Testing javascript/ajax
• Useful when necessary to increase customer confidence
![Page 83: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/83.jpg)
Detailed Scenarios
![Page 84: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/84.jpg)
Detailed ScenariosStory: attendee registers As a potential attendee I want to register for a conference So that I may attend and learn great stuff Scenario: successful registration Given I am viewing the registration form When I enter Name: Joe Smith And I enter E-Mail: [email protected] And I check Tutorials And I click Register Then I should see the Registration Confirmation And it should show Name: Joe Smith And it should show E-Mail: [email protected] And it should show Tutorials: Yes
![Page 85: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/85.jpg)
Detailed Scenarios
... Scenario: missing email address Given I am viewing the registration form When I enter Name: Joe Smith And I do not enter E-Mail And I click Register Then I should see the Registration Form And it should show Email is required
![Page 86: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/86.jpg)
Givens
steps_for :registration do Given "I am viewing the registration form" do visits new_registration_path end Given "a conference named $name" do |name| visits new_conference_path fills_in "Name", :with => name fills_in "Goal", :with => 200 clicks_button endend
![Page 87: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/87.jpg)
Whens
steps_for :registration do When "I enter $label: $value" do |label, value| fills_in label, :with => value end When "I do not enter $label" do |label| # no-op - doc purposes only endend
![Page 88: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/88.jpg)
Whens
steps_for :registration do When "I select $label" do |label| selects label end When "I check $label" do |label| checks label end When "I click $button" do |button| clicks_button button endend
![Page 89: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/89.jpg)
steps_for :registration do Then /I should see the Registration (Form|Confirmation)/ do |form_or_confirmation| case form_or_confirmation when "Form" response.should render_template("registrations/new") when "Confirmation" r = Registration.find(:all, :order => 'id').last response.should render_template("registrations/show") end end Then "it should show $text" do |text| response.should include_text(text) endend
Thens
![Page 90: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/90.jpg)
Detailed Scenarios
• More “design up front” feel vs “story as token for conversation”
• Scenarios are more subject to changes from customer
• Steps are more granular
• Easier to write
• Easier to change
![Page 91: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/91.jpg)
Multiple Sessions
![Page 92: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/92.jpg)
Multiple Sessions
Story "can not view other group's calendar", %( As a member of one group with calendars I do not want members of other groups to see my calendars So that my data is kept private), :type => RailsStory, :steps_for => [ :users_and_groups, :calendars, :navigation] do
...end
![Page 93: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/93.jpg)
Multiple SessionsStory "can not view other group's calendar", %( ... Scenario "two users, two groups, two calendars" do Given "a group named Group1" And "a group named Group2" And "Group1 has a calendar named Calendar1" And "Group2 has a calendar named Calendar2" And "a Group1 member named Person1 is logged in" And "a Group2 member named Person2 is logged in"
When "Person1 visits the calendar list" Then "he should see Calendar1" And "he should not see Calendar2" When "Person2 visits the calendar list" Then "she should see Calendar2" And "she should not see Calendar1" endend
![Page 94: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/94.jpg)
Given
Given "a group named $group" do |group| set_ivar :group, group, Group.create!(:name => group) end Given "a $group member named $name is logged in" do |group, name| create_user_named(name) do |user| user.activate user.groups << get_ivar(:group, group) end login_as(name) end
![Page 95: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/95.jpg)
When
When "$person visits the $page" do |person, page| page_map = { "calendar list" => "/calendars" } @current_session = get_ivar(:session, person) @current_session.visits page_map[page] end
![Page 96: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/96.jpg)
Then
Then /(he|she) (should|should not) see (.*)/ do |_, yes_or_no, calendar|
if yes_or_no == 'should' @current_session.response.should include_text(calendar) else @current_session.response.should_not include_text(calendar) endend
![Page 97: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/97.jpg)
Multiple Sessionsdef create_user_named(login, password=login) User.find_by_login(login).destroy rescue nil user = User.create!( :login => login, :password => password, :password_confirmation => password, :email => "#{login}@company.com" ) yield user if block_given? userend
def login_as(login, password=login) set_ivar :session, login, open_session { |user| user.visits "/sessions/new" user.fills_in :login, :with => login user.fills_in :password, :with => password user.clicks_button }end
![Page 98: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/98.jpg)
Multiple Sessions
module InstanceVariableHelpers def set_ivar(type, name, obj) instance_variable_set ivar_name(type, name), obj end
def get_ivar(type, name) returning instance_variable_get(ivar_name(type, name)) do |obj| yield obj if block_given? end end private def ivar_name(type, name) "@#{type}_#{name.gsub(/[ -]/,'_').gsub('&','and')}" endend
![Page 99: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/99.jpg)
Questions?
![Page 100: Integration Testing in Ruby with RSpec’s Story Automation ...assets.en.oreilly.com/1/event/6/Integration Testing... · RSpec’s Story Automation Framework David Chelimsky articulatedman.com](https://reader033.vdocuments.site/reader033/viewer/2022043001/5f797bb65c5d9f763b2bbe3e/html5/thumbnails/100.jpg)
Thank You
• rspec.info
• blog.davidchelimsky.net
• articulatedman.com