IronRuby 0.9, Cucumber and the never-ending story

August 13th, 2009 by Xerxes Leave a reply »

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:\source\ruby\calculator>icucumber features
Feature: Addition
In order to save time
as a math n00b
I want to be able to add 2 numbers

wrong 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)

features\addition.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 number  into 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      |

 

features\step_definitions\calculator_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
lib\calculator.rb

class Calculator
	def add(x, y)
		return x+y
	end
end
Bookmark this post:
  • DotNetKicks
  • DZone
  • TwitThis
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati

Related posts:

  1. Ruby and .NET for the uninitiated Coming with no experience in both Ruby or IronRuby, this...
  2. Specification Testing in .NET using Ruby Not long ago, I posted a big fat blat of...
  3. Struct Constructor Initialisation I’m working on a personal project atm (more details to...
  4. Google Search Appliance (GSA) Metadata Limitations The GSA is an expensive and very proprietary search box...
  5. Poor-man’s Benchmarking in Ruby As part of evaluating several libraries for specification testing in...

1 comment

  1. Xerxes says:

    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