本文介绍了LoadError需要gem:path或者git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个非常奇怪的问题。

我在github上创建了一个gem来做一些修改,克隆了我的本地机器上的repo,并更改了另一个项目的Gemfile以从我的本地存储库中获取gem来测试它。不幸的是,在我的ruby脚本中需要gem的时候,我得到了一个LoadError。

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

我的Gemfile内容:

  source'http://rubygems.org 

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

套餐输出:

  $ bundle --no-cache 
解析依赖关系...

使用彩色(1.2)
使用highline(1.6.19)
在/ home / benny / workspaces / steps使用来自源代码的步骤(1.0.2)
使用捆绑器(1.3.5)
您的捆绑包已完成!
使用`bundle show [gemname]`查看捆绑的gem的安装位置。


$显示步骤
/ home / benny /工作区/步骤

通过irb测试正常工作:

  $ bundle exec irb 
1.9.3-p392 :001>要求'rubygems'
=>假
1.9.3-p392:002>需要'步骤'
=> true

通过脚本测试不起作用:

  $ 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':无法加载这样的文件 - 步骤(LoadError )从/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:在< main>'

我现在很困惑。如果我使用:git而不是:使用本地git repo或github回购的路径,也是如此。

h2_lin>解决方案

您必须在运行test.rb之前加载bundler环境

  bundle exec ruby​​ test.rb 


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?

解决方案

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

bundle exec ruby test.rb

这篇关于LoadError需要gem:path或者git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 18:20