Telling Stories With RSpec

2,720 views
2,556 views

Published on

An introduction to Behaviour Driven Development and User Stories using RSpec and Ruby

Published in: Technology, Economy & Finance
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,720
On SlideShare
0
From Embeds
0
Number of Embeds
47
Actions
Shares
0
Downloads
85
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Telling Stories With RSpec

  1. 1. Telling Stories with RSpec Rahoul Baruah
  2. 2. Functional Specifications • Functionality and Features • Sketches • Pages and pages of text
  3. 3. Big Design Up Front • Estimates for cost and delivery dates • Agreement and sign-off • Misunderstandings • Software is Intangible • Change is inevitable
  4. 4. “Agile” Development • Short descriptions of each feature • Testable and Verifiable • Easy to understand • Easy to manage • Easy to prioritise • Easy to change
  5. 5. RSpec and Behaviour Driven Development • Getting the words right • It should do this • blue.should be_darker_than(turquoise) • Code as Specification
  6. 6. Mock Objects • vat_calculator = mock ‘VAT Calculator’ • invoice.vat_calculator = vat_calculator • invoice.sub_total = 100 • vat_calculator.should_receive(:calculate).with(100).and_re turn(17.5) • invoice.total.should == 117.5
  7. 7. Integration Tests • Test the full stack • Interactions between objects • Written as code
  8. 8. RSpec User Stories • User Stories • Full Stack Testing • Plain Text plus Executables
  9. 9. Story Structure • As a ... • I want ... • So that ...
  10. 10. Scenarios • Different paths • Success and Errors • “Blank Slate”
  11. 11. Given • Set up pre-requisites • Set up state • Given a user called Dave • And Dave is logged in
  12. 12. When • Actions performed by the actor • When I click the ‘profile’ link • When I enter my new password and confirmation • And click the ‘Change my password’ button • Defined in terms of the user interface
  13. 13. Then • Defines the results of your actions • Then I should see my profile page • And it should list how many items I have bought • Defined in terms of the user interface
  14. 14. Steps • Given, When and Then • Text matchers, with parameters • Executable
  15. 15. Test the Full-Stack • Specify in terms of User-Interface elements • Parse the DOM to check for results • Defines the user interface for the customer
  16. 16. Webrat When “Dave logs in” do visit login_path fill_in ‘User Name’, :with => ‘Dave’ fill_in ‘Password’, :with => ‘secret’ click_button ‘Log In’ end
  17. 17. RSpec Matchers Then “Dave’s profile page is shown” do response.should be_success response.should render_template(‘profiles/show’) response.should include_text(“Dave’s profile page”) end
  18. 18. Cucumber • Structure for organising stories and steps • rake features • Is now part of RSpec
  19. 19. Process • Write a Story • Write the first step • Write the specifications for the controllers • Write the controllers • Write the specifications for the models • Write the models • Run the Story • Write the next step
  20. 20. References • RSpec • Cucumber • Webrat • JBehave • Celerity • HTMLUnit

×