Mark Needham

Thoughts on Software Development

Iron Ruby: ‘unitialized constant…NameError’

without comments

I’ve been playing around a bit with Iron Ruby and cucumber following Rupak Ganguly’s tutorial and I tried to change the .NET example provided in the 0.4.2 release of cucumber to call a class wrapping Castle’s WindsorContainer.

The feature file now looks like this:

# 'MyAssembly.dll' is in the 'C:/Ruby/lib/ruby/gems/1.8/gems/cucumber-0.6.4/examples/cs' folder
require 'MyAssembly'
Before do
  @container =

The class is defined roughly like this:

public class OurContainer : IContainerAccessor
        private WindsorContainer container = new WindsorContainer();
        public SwintonContainer()
            container.RegisterControllers(Assembly.GetExecutingAssembly()).AddComponent<IFoo, Foo>();
           // and so on
        public IWindsorContainer Container
            get { return container; }

When I tried to run the feature like so:

icucumber features

I kept getting the following error:

uninitialized constant Our::Namespace::OurContainer (NameError)
C:/Ruby/lib/ruby/gems/1.8/gems/cucumber-0.6.4/examples/cs/features/step_definitons/calculator_steps.rb:13:in `Before'

I’ve come across a few posts where people described the same error and they all suggested that IronRuby was unable to find the class that I was trying to call in the code.

I decided to try calling another class from the assembly to see if that was the problem but that worked fine so there wasn’t a problem with locating the class.

Somewhat by coincidence I was looking at the assembly again in Reflector and tried to look at the constructor of the ‘OurContainer’ class and was asked to give the location of the ‘Castle.Windsor’ assembly which it uses internally.

I didn’t have that assembly or any of its dependencies in the ‘C:/Ruby/lib/ruby/gems/1.8/gems/cucumber-0.6.4/examples/cs’ folder but once I’d included those it all worked fine again!

Be Sociable, Share!

Written by Mark Needham

April 25th, 2010 at 5:27 pm

Posted in .NET,Ruby

Tagged with , ,