Iron Ruby: 'unitialized constant...NameError'
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 = Our::Namespace::OurContainer.new.Container
end
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!
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.