the why behind tdd/bdd and the how with rspec
DESCRIPTION
A brief introduction to the why behind TDD and an explanation on how BDD builds on that. A quick walk through of the ruby BDD framework, rspec.TRANSCRIPT
![Page 1: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/1.jpg)
The why behind TDD/BDD and the how with RSpec
![Page 2: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/2.jpg)
![Page 3: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/3.jpg)
$ whois benmabey.com
![Page 4: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/4.jpg)
Registrant: Ben Mabey
Programming Ruby Since: may-2006BDDing it Since: may-2007Employer: Alliance Health Networks
$ whois benmabey.com
![Page 5: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/5.jpg)
Registrant: Ben Mabey
Programming Ruby Since: may-2006BDDing it Since: may-2007Employer: Alliance Health Networks
$ whois benmabey.com
![Page 6: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/6.jpg)
Why do we test?
![Page 7: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/7.jpg)
Why do we test?
Confidence. Verification that our system behaves as it is suppose to.
![Page 8: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/8.jpg)
Why do we test?
Confidence. Verification that our system behaves as it is suppose to.
This can be done manually or can be automated. Automation is clearly our friend...
![Page 9: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/9.jpg)
Why automation?
![Page 10: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/10.jpg)
Why automation?
Confidence. Regression Tests!
![Page 11: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/11.jpg)
Why automation?
Confidence. Regression Tests!
Refactoring - Shortened feedback loop makes improving our design much easier and less painful.
![Page 12: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/12.jpg)
Riddle me this...Which tests instill more confidence of a
system’s behavior in you?(Assume they have the same coverage.)
![Page 13: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/13.jpg)
Riddle me this...Which tests instill more confidence of a
system’s behavior in you?(Assume they have the same coverage.)
Tests written after functionality is added.
![Page 14: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/14.jpg)
Riddle me this...Which tests instill more confidence of a
system’s behavior in you?(Assume they have the same coverage.)
Tests written after functionality is added.
Tests written before functionality is added.
![Page 15: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/15.jpg)
Riddle me this...Which tests instill more confidence of a
system’s behavior in you?(Assume they have the same coverage.)
Tests written after functionality is added.
Neither. Both provide equal confidence.
Tests written before functionality is added.
![Page 16: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/16.jpg)
Why test first then?
![Page 17: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/17.jpg)
Why test first then?Most of us aren’t disciplined enough to test last. Once we have manually tested the system taking the time to write an automated test seems like a pain.
![Page 18: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/18.jpg)
Why test first then?Most of us aren’t disciplined enough to test last. Once we have manually tested the system taking the time to write an automated test seems like a pain.
Code that isn’t written with tests in mind tends to be very difficult to test without refactoring it first.
![Page 19: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/19.jpg)
Clear up a common misconception...
![Page 20: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/20.jpg)
Clear up a common misconception...
TDD != writing tests first
![Page 21: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/21.jpg)
Clear up a common misconception...
TDD != writing tests first
TDD =~ writing test first.. but
![Page 22: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/22.jpg)
Clear up a common misconception...
TDD != writing tests first
TDD =~ writing test first.. but
TDD isn’t about testing...
![Page 23: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/23.jpg)
Clear up a common misconception...
TDD != writing tests first
TDD =~ writing test first.. but
TDD isn’t about testing...
TDD is about DESIGN
![Page 24: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/24.jpg)
Clear up a common misconception...
TDD != writing tests first
TDD =~ writing test first.. but
TDD isn’t about testing...
TDD is about DESIGN
RED -> GREEN -> REFACTOR
![Page 25: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/25.jpg)
Design is aPROCESS
not aPHASE
The TDD cycle of RED->GREEN->REFACTOR enablesyou to iterate over your design constantly by
removing duplication (refactoring). Testing units in isolation allows you to achieve high cohesion and
loose coupling regularly.
![Page 26: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/26.jpg)
Side benefits of TDD are...
![Page 27: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/27.jpg)
Side benefits of TDD are...Verification of behavior.
![Page 28: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/28.jpg)
Side benefits of TDD are...Verification of behavior.
Documentation.
![Page 29: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/29.jpg)
Side benefits of TDD are...Verification of behavior.
Documentation.“The act of writing a unit test is more an act of design than of verification. It is also more an act of documentation than of verification. The act of writing a unit test closes a remarkable number of feedback loops, the least of which is the one pertaining to verification of function” -”Uncle” Bob Martin
![Page 30: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/30.jpg)
Riddle me that...Which tests instill more confidence of a
system’s design and long term maintainability?
![Page 31: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/31.jpg)
Riddle me that...Which tests instill more confidence of a
system’s design and long term maintainability?
Tests written after functionality is added.
![Page 32: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/32.jpg)
Riddle me that...Which tests instill more confidence of a
system’s design and long term maintainability?
Tests written after functionality is added.
Tests written with good TDD skillz.
![Page 33: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/33.jpg)
Riddle me that...Which tests instill more confidence of a
system’s design and long term maintainability?
Tests written after functionality is added.
It depends. Are you Bob Martin or Jim Coplien? :p
Tests written with good TDD skillz.
![Page 34: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/34.jpg)
Riddle me that...Which tests instill more confidence of a
system’s design and long term maintainability?
Tests written after functionality is added.
It depends. Are you Bob Martin or Jim Coplien? :p
Tests written with good TDD skillz.
I’m with Uncle Bob on this one *when* TDD is done right...
![Page 35: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/35.jpg)
So why BDD?
![Page 36: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/36.jpg)
So why BDD?
Doing TDD right andunderstanding what it is
all about is hard.
![Page 37: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/37.jpg)
So why BDD?Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 38: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/38.jpg)
So why BDD?
“I had a problem. While using and teaching agile practices like test-driven development (TDD) on
projects in different environments, I kept coming across the same confusion and misunderstandings.
Programmers wanted to know where to start, what to test and what not to test, how much to test in one go, what to call their tests, and how to understand
why a test fails.”
Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 39: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/39.jpg)
So why BDD?
“The deeper I got into TDD, the more I felt that my own journey had been less of a wax-on, wax-off process of gradual mastery than a series of blind
alleys. I remember thinking ‘If only someone had told me that!’ far more often than I thought ‘Wow, a door has opened.’ I decided it must be possible to present TDD in a way that gets straight to the good stuff
and avoids all the pitfalls.”
Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 40: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/40.jpg)
So why BDD?
“My response is behaviour-driven development (BDD). It has evolved out of established agile practices and
is designed to make them more accessible and effective for teams new to agile software delivery. Over time, BDD has grown to encompass the wider picture of agile analysis and automated acceptance
testing.”
Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 41: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/41.jpg)
BDD with RSpec
![Page 42: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/42.jpg)
BDD with RSpecAcceptance Test Driven Testing
![Page 43: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/43.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
![Page 44: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/44.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
![Page 45: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/45.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
Test Driven Development with a vocabulary that focuses on behavior not tests.
![Page 46: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/46.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
Test Driven Development with a vocabulary that focuses on behavior not tests.
Story Framework
![Page 47: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/47.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
Test Driven Development with a vocabulary that focuses on behavior not tests.
Story Framework
As a.. I want.. So that..
![Page 48: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/48.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
Test Driven Development with a vocabulary that focuses on behavior not tests.
Story Framework
As a.. I want.. So that..
Scenarios - Ruby or plain text
![Page 49: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/49.jpg)
BDD with RSpecAcceptance Test Driven Testing
Business Analysis
Executable Acceptance Criteria
Test Driven Development with a vocabulary that focuses on behavior not tests.
Story Framework
As a.. I want.. So that..
Scenarios - Ruby or plain text
Example Framework - DSL for specifying behavior
![Page 50: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/50.jpg)
So... how does this help?Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 51: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/51.jpg)
So... how does this help?
“I had a problem. While using and teaching agile practices like test-driven development (TDD) on
projects in different environments, I kept coming across the same confusion and misunderstandings.
Programmers wanted to know where to start, what to test and what not to test, how much to test in one go, what to call their tests, and how to understand
why a test fails.”
Introducing BDD - Dan Northhttp://dannorth.net/introducing-bdd
![Page 52: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/52.jpg)
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 53: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/53.jpg)
outside-in
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 54: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/54.jpg)
outside-in
user stories
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 55: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/55.jpg)
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 56: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/56.jpg)
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 57: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/57.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
![Page 58: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/58.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Story: (one line describing the story)
![Page 59: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/59.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Story: (one line describing the story)
As a [role]
![Page 60: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/60.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Story: (one line describing the story)
As a [role]I want to [some action]
![Page 61: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/61.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Story: (one line describing the story)
As a [role]I want to [some action]So that [business value!]
![Page 62: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/62.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
![Page 63: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/63.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as Scenarios
![Page 64: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/64.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: title
![Page 65: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/65.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]
![Page 66: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/66.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]And [additional context]
![Page 67: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/67.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]And [additional context]When [event]
![Page 68: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/68.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]And [additional context]When [event]Then [outcome]
![Page 69: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/69.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]And [additional context]When [event]Then [outcome]
Scenario: another variant
![Page 70: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/70.jpg)
What’s in a story?http://dannorth.net/whats-in-a-story - Dan North
Acceptance Criteria as ScenariosScenario: titleGiven [some context]And [additional context]When [event]Then [outcome]
Scenario: another variantGiven...
![Page 71: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/71.jpg)
Story Time
![Page 72: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/72.jpg)
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
![Page 73: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/73.jpg)
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
very little-focused
![Page 74: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/74.jpg)
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
very little-focused
sentence template
![Page 75: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/75.jpg)
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
very little-focused
sentence template
documentation
![Page 76: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/76.jpg)
Example Framework
Story Framework
outside-in
user stories
anything else
So... how does this help?where to start
what to test
what not to test
how much to test in one go
what to call their tests
understand why a test fails
idea taken from http://www.slideshare.net/Robbert/bdd-rspec
very little-focused
sentence template
documentation
![Page 77: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/77.jpg)
Test::Unit to RSpec
![Page 78: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/78.jpg)
Test::Unit to RSpec
class DogTest
![Page 79: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/79.jpg)
Test::Unit to RSpec
class DogTest describe Dog
![Page 80: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/80.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark
![Page 81: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/81.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
![Page 82: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/82.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx
![Page 83: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/83.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx object.should be_xxx
![Page 84: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/84.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx object.should be_xxx
def setup
![Page 85: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/85.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx object.should be_xxx
def setup before(:each) {}
![Page 86: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/86.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx object.should be_xxx
def setup before(:each) {}
def teardown
![Page 87: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/87.jpg)
Test::Unit to RSpec
class DogTest describe Dog
def test_bark it “should bark”
assert_xxx object.should be_xxx
def setup before(:each) {}
def teardown after(:each) {}
![Page 88: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/88.jpg)
Matchersa.should == b, a.should equal(b), a.should eql(b)
a.should_not ....
a.should_be nil
a.should be_happy # calls a.happy?
a.should match(/regex/), a.should =~ /regex/)
lambda { a.blah }.should raise_error
http://rspec.info/rdoc/classes/Spec/Matchers.html
![Page 89: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/89.jpg)
Mocks
![Page 90: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/90.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
![Page 91: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/91.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
Not concerned about the state. Just how it interacts with other objects.
![Page 92: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/92.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
Not concerned about the state. Just how it interacts with other objects.
Helps drive design.
![Page 93: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/93.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
Not concerned about the state. Just how it interacts with other objects.
Helps drive design.
Allows you to test collaborators in isolation.
![Page 94: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/94.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
Not concerned about the state. Just how it interacts with other objects.
Helps drive design.
Allows you to test collaborators in isolation.
Need stories to make sure it all “works”.
![Page 95: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/95.jpg)
MocksInteraction-Based Testing
http://www.martinfowler.com/articles/mocksArentStubs.html
http://nat.truemesh.com/archives/000342.html
Not concerned about the state. Just how it interacts with other objects.
Helps drive design.
Allows you to test collaborators in isolation.
Need stories to make sure it all “works”.
![Page 96: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/96.jpg)
Mocks
RSpec Built in Mocking framework
Mocha
FlexMock
![Page 97: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/97.jpg)
Example Time
![Page 98: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/98.jpg)
TipsOne Expectation per test
Write Expectation first
Isolation
Detect Code smells in setup with stubs
ExampleGroup level shared behavior helpers
Blocks are your friend
spec, autotest, drb server, RSpactor
Continuous Integration - CC.rb
![Page 99: The WHY behind TDD/BDD and the HOW with RSpec](https://reader031.vdocuments.us/reader031/viewer/2022013100/5482bfdfb4af9f7d148b4914/html5/thumbnails/99.jpg)
Resourceshttp://rspec.info/
http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/
http://blog.davidchelimsky.net/
Recommended Reading
Test Driven Development: By Example, by Kent Beck
Test-Driven Development: A Practical Guide, by David Astels
Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans
Refactoring: Improving the Design of Existing Code by Martin Fowler
Working Effectively with Legacy Code by Michael Feathers
Agile Software Development, Principles, Patterns, and Practices by Bob Martin