RSpec tasks, JRuby and rvm

I’ve been playing with rvm these days and I had a bad surprise today.

$ rvm install jruby
$ rvm jruby
$ rake test

failed…

Of course you didn’t understand. I didn’t explain yet…

I’ve written a Rakefile following RSpec homepage instructions and adding
some options to ruby (namely “–ng”, for working with nailgun support).
But the error seems to be related to gems access. If I run the RSpec
command from a terminal where I executed “rvm jruby”, it works. In
another terminal it won’t work.

I’m testing a Java Maven project with JRuby and RSpec. It was working
prior to rvm use. But calling the “ruby” executable using the full path,
as RSpec tasks does, doesn’t seem to suffice. “rvm jruby” probably sets
up a proper environment that is not reproduced by RSpec when calling the
configured ruby interpreter.

Of course I could contact the RVM developers about this, but I would
like to understand first why RSpec needs to spawn a separate process in
its task… Does anyone here knows the reason?

Thanks in advance…

Rodrigo.


Faça ligações para outros computadores com o novo Yahoo! Messenger

On May 6, 2010, at 6:42 PM, Rodrigo Rosenfeld R. wrote:

I’ve written a Rakefile following RSpec homepage instructions and adding some options to ruby (namely “–ng”, for working with nailgun support). But the error seems to be related to gems access. If I run the RSpec command from a terminal where I executed “rvm jruby”, it works. In another terminal it won’t work.

I’m testing a Java Maven project with JRuby and RSpec. It was working prior to rvm use. But calling the “ruby” executable using the full path, as RSpec tasks does, doesn’t seem to suffice. “rvm jruby” probably sets up a proper environment that is not reproduced by RSpec when calling the configured ruby interpreter.

Of course I could contact the RVM developers about this, but I would like to understand first why RSpec needs to spawn a separate process in its task… Does anyone here knows the reason?

This has been an open issue for a long time. We wrote the task that way
originally because there are some cases in which we need to spawn a
separate process (if you want to run rcov, for example). What we’d like
to do is have it shell out in those cases, but otherwise just invoke the
rspec runner directly. Just haven’t prioritized it. If anybody wants to
make a patch for this, I’d be glad to merge it (assuming it’s sound and
spec’d). We need this for rspec 1 and rspec 2.

David

The same problem, can’t use ‘rake spec’, here’s quick workaround, use

rake spec:isolated

namespace :spec do
desc “Run RSpec code exapmples in isolated mode (every spec file in
different Ruby process)”
task :isolated do
Dir.glob(“spec/**/[^_]*_spec.rb”).each do |spec_file|
Kernel.system “rspec #{spec_file}”
end
end
end

it’s terribly slow, btw :slight_smile: