Unsupported use case: calling rspec from rake using JRuby?

Skip to first unread message


Feb 4, 2011, 9:49:13 AM2/4/11
to ruby-bundler
The short version: a command like
jruby -S bundle exec jruby -S bundle exec ruby -e "puts 'foo'"
results in
Could not find RubyGem bundler (>= 0) (Gem::LoadError)
because the first 'bundle exec' executes the second 'bundle' command
in an environment in which the "gem 'bundler', version" line in the
bundle executable fails, because the Gem.path of Rubygems only
contains the path where Bundler installed the gems of the project,
which does not contain the path of the bundler gem itself.

The long version: I have a rakefile, which defines an
RSpec::Core::RakeTask. The rakefile contains the snippet
require 'rubygems'
require 'bundler/setup'
Bundler.require :default, :test
because the rspec gem is present in the bundle (and I need other gems
from the bundle to execute other rake tasks).

If I now call:
jruby -S rake spec
the RakeTask subsequently runs
jruby -S bundle exec rspec <some of my spec files>
which fails with
Could not find RubyGem bundler (>= 0) (Gem::LoadError)

After some digging, this makes sense, from a 'how it works'-point of
view. After the Bundler.require in the rakefile, the Gem.path of
Rubygems has been reduced to the paths where bundler has installed the
gems of the Gemfile of this project. Of course, the bundler gem itself
is not present there, because it is must be a system level gem.
However, when

jruby -S bundle exec rspec <some of my spec files>

is executed by rake, the first thing the 'bundle' command (present in
$JRUBY_HOME/bin) does is requiring the bundler gem. This fails,
because the bundler gem cannot be found on the path where it told
Rubygems to look for gems.

This issue does not depend on rake or rspec. The simplest case,
without rake or rspec, that demonstrates the issue is:

jruby -S bundle exec jruby -S bundle exec ruby -e "puts 'foo'"

This will fail with the same error, because the first 'bundle exec'
has created an environment in which the second 'bundle exec' cannot
require the bundler gem.

Now I wonder whether this is a bug, because I would not expect the
mangling of the Rubygems Gem.path to carry over to a new process. When
jruby -S bundle exec rspec <spec-files>
runs, this is the output of some Rubygems instrumentation in self.dir,
self.path, self.set_home and self.set_paths in rubygems.rb:

Initializing @gem_path from '', '' and [$HOME/.gem/jruby/1.8/, $HOME/
Initializing @gem_home from $HOME/dev/project/trunk/vendor/bundle/
jruby/1.8, '' and $HOME/bin/jruby-1.5.6/lib/ruby/gems/1.8
@gem_home has been set to: $HOME/dev/project/trunk/vendor/bundle/
@gem_path has been set to: ["$HOME/dev/project/trunk/vendor/bundle/

I would expect this use case to be supported, but I haven't been able
to find anything that suggests anyone else is suffering from this
issue. Is there a different solution to this problem or can we only
patch this is Bundler, by having it add it's own gem path to the paths
it supplied to Rubygems?


Feb 6, 2011, 3:07:24 AM2/6/11
to ruby-bundler
I just realized there is an even simpler showcase, to show that
Rubygems cannot the Bundler gem in in the bundle, when invoked with

jruby -S bundle exec bundle show
`report_activate_error': Could not find RubyGem bundler (>= 0)

from /home/ivo/bin/jruby/lib/ruby/site_ruby/1.8/rubygems.rb:211:in
from /home/ivo/bin/jruby/lib/ruby/site_ruby/1.8/rubygems.rb:1056:in
from /home/ivo/bin/ruby-enterprise/bin/bundle:18

The same without the starting j works just fine.

Rhett Sutphin

Feb 6, 2011, 2:57:43 PM2/6/11
to ruby-b...@googlegroups.com
Hi Ivo,

I'm taking a stab here, but are you sure that bundler is installed for jruby? According to that stack trace, the `bundle` executable that's being executed by jruby is coming from REE's binpath.


> --
> You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
> To post to this group, send email to ruby-b...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-bundler...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-bundler?hl=en.


Feb 8, 2011, 2:32:42 PM2/8/11
to ruby-bundler
Hi Rhett,

I think that is a symptom of the problem ;).
jruby -S gem list
jgem list
both show the bundler gem.

jgem which bundler
shows it is available at

best regards,
Reply all
Reply to author
0 new messages