【问题标题】:cannot load gems in test environment无法在测试环境中加载 gem
【发布时间】:2014-09-02 21:24:05
【问题描述】:
  • 我的应用可以正常工作。
  • 我以前可以运行测试,但现在由于某种原因不能运行。
  • 从现在到那时发生的事情是我对 activesupport 进行了供应(但我已经撤消了这些更改,实际上我在一个完全独立/不相关的分支中)。
  • 我在activesupport 上运行的两个我不熟悉的命令是bundle --deploymentbundle --no-deployment。同样,我相信我取消了与这些更改相关的所有内容(至少就git status 而言 - 我总是运行git status,并且知道所有代码库变化)。

我知道其他人也有类似的问题,但不是这个确切的问题:https://stackoverflow.com/search?q=require+cannot+load+such+file+LoadError

我在玩弄供应商 activesupport 以下: How to vendor a modified version of active_support such that it is used in my Rails app?

当我尝试将供应商化的activesupport 分支推送到staging 时遇到了麻烦: Where is 'elsewhere' in "run `bundle install` elsewhere"?

无论如何,关键是 我的应用程序可以运行(即所有 gem 显然都已安装,GemfileGemfile.lock 完好无损),但我无法运行测试

/Users/bsimpson/.rvm/gems/ruby-2.0.0-p481@books/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- minitest/rails (LoadError)
  from /Users/bsimpson/.rvm/gems/ruby-2.0.0-p481@books/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
  from /Users/bsimpson/.rvm/gems/ruby-2.0.0-p481@books/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
  from /Users/bsimpson/.rvm/gems/ruby-2.0.0-p481@books/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
  from /Volumes/MyHD/Users/bsimpson/Dev/books/books/test/test_helper.rb:10:in `<top (required)>'
  from test/controllers/photos_controller_test.rb:1:in `require'
  from test/controllers/photos_controller_test.rb:1:in `<main>'

如果我注释掉test/test_helper.rb10 行,它只会抱怨下一个require 行。

dependencies.rb:229:in `require': cannot load such file -- minitest/rails/capybara (LoadError)
...
test/test_helper.rb:14:in `<top (required)>'

当我注释掉14 行时,它会抱怨下一行require,依此类推...

所以似乎在test 环境中,看不到宝石。想法?

.bundle/config

---
BUNDLE_WITHOUT: development:test

【问题讨论】:

  • 你能把你的.bundle/config文件的内容包括进来吗?
  • 谢谢。我已将其添加到我的问题中。

标签: ruby-on-rails git bundler


【解决方案1】:

BUNDLE_WITHOUT: development:test 配置告诉 Bundler 不要从 developmenttest 组加载 gem。由于这是您唯一的配置设置,因此您可以安全地删除 .bundle/config 文件,然后一切都会恢复正常。

或者,您可以保留文件并仅删除该行。

是否有可能当您运行bundle --deployment 时,您实际上运行了bundle --deployment --without development test?这些选项通常一起使用,传递给bundle install(或不带子命令的bundle,默认为install)的选项在bundle/.config 文件中被记住。这些选项在被显式删除之前是“粘性的”,因此如果您使用一次--without 标志,则需要编辑文件以恢复这些组。

还要注意.bundle/config 通常被排除在 git 之外,所以检查git status 不会告诉你它是否改变了。这些设置通常与机器相关,因此最好将其排除在 git 之外。

【讨论】:

  • 非常感谢!我将在 23 小时内奖励你。
  • 顺便说一下,我检查了我的命令日志,结果发现我也运行了bundle install --without development test——但没有运行bundle --deployment --without development test(即不包括--deployment)。话说,你是怎么知道bundle的这些细节的?
  • OK 是的 --deployment--without 是独立的,但通常一起使用。我在业余时间从事 Bundler 工作,但文档非常详尽 bundler.io
  • 很高兴听到您再次启动并运行 :-)
猜你喜欢
  • 2013-09-07
  • 1970-01-01
  • 2021-11-22
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-04
相关资源
最近更新 更多