在我正在处理的 rails 项目中,我使用此 Gemfile(部分)插入了对 rspec、cucumber 和 autotest 的支持
gem 'rspec-rails'
gem 'cucumber-rails'
gem 'autotest-standalone'
gem 'autotest-rails-pure'
gem 'zentest-without-autotest'
但是,为了使用自动测试运行测试,我需要执行,bundle exec autotest
否则它会失败并显示此消息
$ autotest
loading autotest/cucumber_rails_rspec_rspec2
Error loading Autotest style autotest/cucumber_rails_rspec_rspec2 (no such file to load -- autotest/cucumber_rails_rspec_rspec2). Aborting.
现在我正在 Mac 上开发,我想启用 autotest-growl 和 autotest-fsevents gem,但是如果我在我的~/.autotest
require 'autotest/growl'
require 'autotest/fsevent'
然后我需要在 Gemfile 中插入相应的 gem,一切正常,但它破坏了我的 CI 服务器(在 Linux 上)上的构建
如何在不为本地和 CI 环境维护不同的 Gemfile 的情况下解决这个问题?
编辑:
目前我用 Gemfile 中的这些行解决了
if RUBY_PLATFORM.downcase.include?("darwin") # I'm on Mac
gem 'autotest-fsevent'
gem 'autotest-growl'
end
它在本地和 CI 服务器上都可以工作,我不知道它是否会弄乱一些东西,目前它似乎可以完美地工作。
任何更清洁的方法仍然受到欢迎。
编辑2:
我切换到组解决方案。虽然之前的monkeypatch 在开发和持续集成中运行良好,但如果您使用capistrano bundler 任务进行部署或使用bundle install --deployment
选项(建议在生产中使用) ,它会在生产中出现错误
使用该if RUBY_PLATFORM.downcase.include?("darwin")
行时,您将在部署时收到此错误。
# bundle install --deployment --without development test
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have deleted from the Gemfile:
* autotest-fsevent
* autotest-growl
所以我对这个问题的最终解决方案是在给定的组中包含特定于平台的 gem,比如 osx,然后在生产和 CI 服务器上使用 bundle 排除它。
如果您使用 capistrano 进行部署,请将其放入您的config.rb
set :bundle_without, [:development, :test, :osx]
# capistrano bundler task
require "bundler/capistrano"