BDD for Ruby
-
Upload
wei-jen-lu -
Category
Technology
-
view
2.144 -
download
0
Transcript of BDD for Ruby
Behavior Driven Development for Ruby
Lu Wei Jen
TDD vs. BDD
TDD
Test Driven Development
Writing tests before writing the code being tested.
Red/Green/Refactor
TDD
BDD
Behavior Driven Development
Getting the word right was the starting point for the development of BDD.
BDDTDDTDD
BDD methods
(sentence template)
BDD tools for ruby
Cucumber
RSpec
Cucumber
Cucumber
Home: http://cukes.info/
GitHub: http://github.com/aslakhellesoy/cucumber/
Install
git clone \ git://github.com/aslakhellesoy/cucumber.git
sudo rake install_gem
Features
Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers
Scenario Outline: Add two numbers Given I have entered into the calculator And I have entered into the calculator When I press Then the result should be on the screen
Examples: | input_1 | input_2 | button | output | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
:
:
: | _1 | _2 | | | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
Cucumber Keywords
feature: background: scenario: | scenario_outline: | examples: given: when: then: and: | but:
RSpec
Home: http://rspec.info/
GitHub: http://github.com/dchelimsky/rspec
Install: sudo gem install rspec
Rspec Example
describe Calculator do context "" do before(:each) do @calculator = Calculator.new end it ""do @calculator.push.should an_instance_of(Fixnum) end end end
MWorking from the Outside-In
BDD Step with Cucumber and RSpec
Example
User Story
Actor
Behaviour(for client)
Example: feature
:
: Ping ping pong
Example: Passing Feature
Example: Step Definitions
Example: RSpec
Q and A