12

I've got a really strange problem here.

I forked a gem on github to do some modifications, cloned my repo on my local machine, made the changes and changed the Gemfile of another project to fetch the gem from my local repository for testing it. Unfortunately I get a LoadError while requiring that gem in my ruby script.

rvm current => ruby-1.9.3-p448
ruby --version => ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
bundle --version => Bundler version 1.3.5

Content of my Gemfile:

source 'http://rubygems.org

gem 'steps', :path => "/home/benny/workspace/steps"

Bundle output:

$ bundle --no-cache
Resolving dependencies...

Using colored (1.2) 
Using highline (1.6.19) 
Using steps (1.0.2) from source at /home/benny/workspaces/steps 
Using bundler (1.3.5) 
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.


$ bundle show steps
/home/benny/workspaces/steps

Testing via irb works fine:

$ bundle exec irb
1.9.3-p392 :001 > require 'rubygems'
 => false 
1.9.3-p392 :002 > require 'steps'
 => true

Testing via script doesn't work:

$ cat test.rb
require 'rubygems'
require 'steps'

$ ruby test.rb
/home/benny/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- steps (LoadError)
from /home/benny/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:2:in `<main>'

I'm very confused right now. Same happens if I use :git instead of :path with local git repo or the github repo.

Any ideas?

2 Answers 2

18

You'll have to load the bundler environment before running the test.rb

bundle exec ruby test.rb
Sign up to request clarification or add additional context in comments.

1 Comment

Wow I've been scratching my head for last half hour.... Gem install fines, bundler shows it but you cant load it. Can you please provide a little explanation as to WHY we need to use bundle exec for local gems?
4

You can run with the bundler environment via:

bundle exec ruby script.rb

Or require bundler setup in your script before the gem(s) that are causing the issue.

require 'bundler/setup'

Most links I found out there about this pointed to documentation on Bundler's site, but most all of the links are dead now unfortunately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.