Ruby refinements not working in CI server

linux, ruby, ruby-2.0

Solution

In current release of Ruby 2.0 (2.0.0p0), `using` is an instance method of the top-level object `main`, not that of `Module`. And it's a private method. If you call it in class/module definition or method definition, a RuntimeError is raised.

"The scope of a refinement activated by `main.using` is from the point just after `main.using` is invoked to the end of the file where `main.using` is invoked. However, when `main.using` is invoked in a string given as the first argument of `Kernel#eval`, `Kernel#instance_eval`, or `Module#module_eval`, the end of the scope is the end of the string."

You can read more about this in Refinements Specification.

For your test cases, you can write them with `eval` and pass in the top level bindings, like the test cases in ruby source.

Refinements is still an experimental feature, it may change in future :-)

Problem

I'm having errors within the Jenkins server: ``` $ ruby -v ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] ``` When running rspec, I have the following error: ``` undefined method `using' for #<Class:0x000000026f9c88> (NoMethodError) ``` the exact same code works on my local computer, with ruby2. Here's my version: `ruby 2.0.0dev (2012-12-01 trunk 38126) [x86_64-linux]` Also, it works on irb. It seems that ruby isn't recognizing the `using` statement when running a script. Here's the code: ``` describe "blah" do include TestHelper using TestHelper::BrowserRefinement ... end ``` clarification: the refinement is defined in a different file. I'm scourging the interwebs to see if there's a difference between revisions `r39474` and `r38126`.

Original source