Created
August 26, 2011 12:45
-
-
Save DNNX/1173331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <x> and <y> into the calculator | |
When I press "add" | |
Then the result should be <z> on the screen | |
Examples: | |
| x | y | z | | |
| 2| 2| 4| | |
| -3| -4| -7| | |
| 0| 0| 0| | |
| 100_500| 100_500| 201_000| | |
| 1.25| 2.5| 3.75| | |
| 10| -10| 0| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift File.expand_path('../../lib', __FILE__) | |
require 'calculator' | |
describe Calculator, '#eval' do | |
[ [ 2, 2, 4], | |
[ -3, -4, -7], | |
[ 0, 0, 0], | |
[100_500, 100_500, 201_000], | |
[ 1.25, 2.5, 3.75], | |
[ 10, -10, 0] | |
].each do |x, y, sum| | |
it "should evaluate #{x} + #{y} as #{sum}" do | |
Calculator.plus(x, y).should == sum | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift File.expand_path('../../lib', __FILE__) | |
require 'calculator' | |
describe Calculator, '#eval' do | |
it 'should evaluate 2 + 2 as 4' do | |
Calculator.plus(2, 2).should == 4 | |
end | |
it 'should evaluate (-3) + (-4) as -7' do | |
Calculator.plus(-3, -4).should == -7 | |
end | |
it 'should evaluate 0 + 0 as 0' do | |
Calculator.plus(0, 0).should == 0 | |
end | |
it 'should evaluate 100_500 + 100_500 as 201_000' do | |
Calculator.plus(100_500, 100_500).should == 201_000 | |
end | |
it 'should evaluate 1.25 + 2.5 as 3.75' do | |
Calculator.plus(1.25, 2.5).should == 3.75 | |
end | |
it 'should evaluate 10 + (-10) as 0' do | |
Calculator.plus(10, -10).should == 0 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
namespace Calculator.Test | |
{ | |
[TestFixture] | |
public class CalculatorTest | |
{ | |
[TestCase( 2, 2, Result = 4)] | |
[TestCase( -3, -4, Result = -7)] | |
[TestCase( 0, 0, Result = 0)] | |
[TestCase(100500, 100500, Result = 201000)] | |
[TestCase( 10, -10, Result = 0)] | |
public long ShouldAddTwoNumbers(long x, long y) | |
{ | |
return Calculator.Add(x, y); | |
} | |
} | |
} |
absolutely! cucumber rocks
I have to try making smth similar with specs2 (scala) - will see, which one's better :)
So, you're going to reinvent the wheel, right? :) http://skipoleschris.blogspot.com/2010/11/using-cucumber-with-scala-and-sbt.html
No-no-no, in Soviet Russia Scala we use specs
for BDD :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks gorgeous ~> https://gist.github.com/1173331#file_calculator.feature
great example of human-readable specs