Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (45 sloc) 1.37 KB
# BDD DSL (behavior-driven development domain-specific language)
# 1. Describe behavior in plain text
# in features/addition.feature
=begin
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 <input_1> into the calculator
And I have entered <input_2> into the calculator
When I press <button>
Then the result should be <output> on the screen
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
=end
# 2. Define step definition
# in features/step_definitions/*.rb
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
require 'cucumber/formatter/unicode'
$:.unshift(File.dirname(__FILE__) + '/../../lib')
require 'calculator'
Before do
@calc = Calculator.new
end
After do
end
Given /I have entered (\d+) into the calculator/ do |n|
@calc.push n.to_i
end
When /I press (\w+)/ do |op|
@result = @calc.send op
end
Then /the result should be (.*) on the screen/ do |result|
@result.should == result.to_f
end
# 3. Run and watch it fail
# $ cucumber features/addition.feature
# 4. Write code to make it pass
# ...
# 5. Run again and see it pass
# $ cucumber features/addition.feature
Something went wrong with that request. Please try again.