Instantly share code, notes, and snippets.

# DNNX/CalculatorTest.cs Created Aug 26, 2011

 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 and into the calculator When I press "add" Then the result should be 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|
 \$:.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
 \$:.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
 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); } } }

### remeniuk commented Aug 26, 2011

 looks gorgeous ~> https://gist.github.com/1173331#file_calculator.feature great example of human-readable specs
Owner Author

### DNNX commented Aug 26, 2011

 absolutely! cucumber rocks

### remeniuk commented Aug 26, 2011

 I have to try making smth similar with specs2 (scala) - will see, which one's better :)
Owner Author

### DNNX commented Aug 26, 2011

 So, you're going to reinvent the wheel, right? :) http://skipoleschris.blogspot.com/2010/11/using-cucumber-with-scala-and-sbt.html

### remeniuk commented Aug 26, 2011

 No-no-no, in Soviet Russia Scala we use `specs` for BDD :-)