I’m a big fan of what Cucumber has to offer a .NET developer like myself. What gets me down is the problem that IronRuby never seems *quite* mature enough to run it.
I’ve encountered (what i believe to be) a bug in IronRuby 0.9.0.0. The following feature (with no .NET interop) works using the Ruby interpreter, but fails under IronRuby.
The specification to reproduce the bug is based on a simple calculator performing an addition task. IronRuby barfs with the following error:
D:sourcerubycalculator>icucumber features
Feature: Addition
In order to save time
as a math n00b
I want to be able to add 2 numberswrong number of arguments (1 for 0) (ArgumentError)
c:/Ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.94/bin/../lib/cucumber/ast/feature_element.rb:24:in `name_line_lengths’
:0:in `send’
IronRuby.Libraries:0:in `SendMessageOpt’
:0:in `each’
c:/Ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.94/bin/../lib/cucumber/ast/feature_element.rb:20:in `first_line_length’
IronRuby.Libraries:0:in `Each’
:0:in `collect’…
…
Hopefully the problem turns out to be something weird in my environment, but I’m reproducing the code below in case someone else would like to try it:
(i’ve also pushed it to Github: Ruby Calculator)
featuresaddition.feature
Feature: Addition In order to save time as a math n00b I want to be able to add 2 numbers Scenario: Addition Given I have entered the first number 2 into the calculator And I have entered the second number 3 into the calculator When I call the add method Then the result 5 should be returned Scenario Outline: More Addition Given I have entered the first numberinto the calculator And I have entered the second number into the calculator When I call the method Then the result should be returned Examples: | x | y | method | result | | 2 | 3 | add | 5 | | 1 | 1 | add | 2 | | 0 | 0 | add | 0 | | -2 | 3 | add | 1 |
featuresstep_definitionscalculator_steps.rb
require "spec" require "lib/calculator" Before do @calc = Calculator.new end Given /^I have entered the first number (-?d+) into the calculator$/ do |n| @x = n.to_i end Given /^I have entered the second number (-?d+) into the calculator$/ do |n| @y = n.to_i end When /^I call the add method$/ do @result = @calc.add(@x, @y) end Then /^the result (d+) should be returned$/ do |n| @result.should equal(n.to_i) end
libcalculator.rb
class Calculator def add(x, y) return x+y end end
For anyone who read this post, it turns out there really was a bug in IronRuby and after logging the bug, they patched it up pretty quick!
http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=2008