Bundler在Mac上错过了宝石

时间:2017-09-20 08:30:44

标签: ruby rubygems bundler

我在使用bundler加载gem时遇到问题。仅在我的mac环境中发生。无法通过bundler找到gem,但是当我通过gem install #{gem}全局安装gem时,它可以正常工作。

我想这是特定于环境的东西,但我不确定如何调试它。我在Ubuntu盒子上有相同版本的ruby,ruby-install和chruby以及bundler,但它的工作正常。

到目前为止,我遇到了gems spring-comands-rspec和rack-cors这个问题。

破碎的环境(Mac):

OS: Darwin nb-mjacobus2 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Bundler: 1.15.4
ruby-install: 0.6.1
chruby: 0.3.9
ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

公开错误:

的Gemfile

group :development do
  # ...
  gem 'spring-commands-rspec'
  # ...
end

运行测试

./bin/rspec spec/controller/some_controller_spec.rb:8
/$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- spring-commands-rspec (LoadError)
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.spring.rb:2:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/commands.rb:29:in `<module:Spring>'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/commands.rb:4:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/server.rb:9:in `<top (required)>'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.rubies/ruby-2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client/server.rb:9:in `call'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
        from /$HOME/.gem/ruby/2.4.1/gems/spring-2.0.2/bin/spring:49:in `<main>'

手动安装gem解决了这个问题......

gem install spring-commands-rspec
Fetching: spring-commands-rspec-1.0.4.gem (100%)
Successfully installed spring-commands-rspec-1.0.4
Parsing documentation for spring-commands-rspec-1.0.4
Installing ri documentation for spring-commands-rspec-1.0.4
Done installing documentation for spring-commands-rspec after 0 seconds
1 gem installed

...但是我得到了这个警告:

./bin/rspec spec/pattern_library_controller_spec.rb
WARN: Unresolved specs during Gem::Specification.reset:
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
WARN: Unresolved specs during Gem::Specification.reset:
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Running via Spring preloader in process 53164
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 5284

SomeController
  should respond with a success status code (2xx)

Finished in 0.13193 seconds (files took 0.66951 seconds to load)
1 example, 0 failures

Randomized with seed 5284

知道问题可能是什么?

2 个答案:

答案 0 :(得分:0)

出于某种原因,宝石安装在vendor / bundle内部,但不是全部。正在删除<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cpp" compilerOptions="/unsafe" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </compilers>

.bundle / config的内容是:

rm -rf .bundle vendor/bundle && bundle install

答案 1 :(得分:0)

TL; DR;尝试在if(headers) { Object.assign(reqHeaders, headers); } const payload = { headers: reqHeaders, url: url, method: requestType, timeout: 10000, json: true, followRedirect: true, maxRedirects: 10, body: options.body || {}, fullResponse: true }; return rp(payload).then(function(response) { if (response.statusCode === 401) { throw Error('Token expired'); } return response.body; }); 中将spring-commands-rspec移至test组:

Gemfile

OR group :development # ... # ... end group :test do # ... gem 'spring-commands-rspec' end 如果您需要宝石不仅用于测试。

简而言之:当你在Rails中运行时,有group :development, :test do概念。加载的宝石也依赖于它Environment - Gemfile加载来自相应组的常见宝石和宝石。 默认环境是开发,但Bundler使用测试。因此,当您运行rspec时,如果它们未在 test 组中列出,则不会加载来自 development 组的gems。

<强>更新: 您似乎已在服务器模式中设置了应用(可能是您从部署脚本获得安装命令)。因为在 staging / production 服务器上部署Rails应用程序时,rspec ...目录和.bundle非常典型(例如,gems随本地安装应用程序)。
但在这种情况下,vendor/bundle至少应包含.bundle/config

BUNDLE_PATH