LoadError by requiring a gem with :path or :git

╄→гoц情女王★ 提交于 2019-12-22 04:31:50

问题


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?


回答1:


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

bundle exec ruby test.rb



回答2:


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.



来源:https://stackoverflow.com/questions/18186800/loaderror-by-requiring-a-gem-with-path-or-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!