Ruby on rails 使用bundler进行自动测试的平台特定gems

Ruby on rails 使用bundler进行自动测试的平台特定gems,ruby-on-rails,bundler,autotest,gemfile,Ruby On Rails,Bundler,Autotest,Gemfile,在rails项目中,我使用这个Gemfile(部分)插入了对rspec、cucumber和autotest的支持 但是,为了使用自动测试运行测试,我需要执行bundle exec autotest,否则它将失败并显示此消息 $ autotest loading autotest/cucumber_rails_rspec_rspec2 Error loading Autotest style autotest/cucumber_rails_rspec_rspec2 (no such file t

在rails项目中,我使用这个Gemfile(部分)插入了对rspec、cucumber和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'
然后我需要在gem文件中插入相应的gem,一切正常,但它破坏了我的CI服务器(在Linux上)上的构建

如何在不为本地和CI环境维护不同文件的情况下解决此问题

编辑:

目前,我用Gemfile中的这些行解决了这个问题

if RUBY_PLATFORM.downcase.include?("darwin") # I'm on Mac
  gem 'autotest-fsevent'
  gem 'autotest-growl'
end
它在本地和CI服务器上都能工作,我不知道它是否弄乱了什么,目前看来它工作得很完美

任何更干净的方法都是受欢迎的

编辑2:

我转向了小组解决方案。虽然之前的monkeypatch在开发和持续集成方面都运行良好,但如果您使用capistrano bundler任务进行部署,或者使用
bundle安装--deployment
选项(建议在生产中使用),则在生产中会出现错误

使用
if RUBY\u 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
所以,我对这个问题的最终解决方案是在给定的组(比如osx)中包含特定于平台的gem,然后在生产和CI服务器上使用bundle排除它

如果使用capistrano进行部署,请将其放入
config.rb

set :bundle_without,  [:development, :test, :osx]
# capistrano bundler task
require "bundler/capistrano"

您可以通过利用不同的Gemfile环境(测试、开发、生产)来处理这个问题

当CI服务器是您的“生产”环境时,您的本地机器可以进行开发

记住这一点,您可以根据环境编辑GEM文件以使用适当的GEM


编辑:对不起,我想我扫描你的文章太快了。但是,您可以将
~/.autotest
添加到
.gitignore
,这样它就不会包含在您的CI服务器中。

您可能希望在GEM文件中使用组,例如:

group :development do
  gem "autotest-growl"
  gem "autotest-fsevents"
end

在您使用的服务器上:
$bundle install--无需开发

~/.autotest
文件不是问题,因为它在我的主目录中,而不是在项目根目录中。问题是它需要两个gem,但它们没有列在Gemfile中,因此在bundle上下文中,需要这些gem会引发加载错误。我希望避免使用其他方法(在Gemfile中管理不同的环境)来避免跨环境的配置重复。好的,我更了解您的问题。但是你是说你不喜欢在你的文件中有不同的“测试、开发、生产”组吗?因为这正是这些团体的目的;diff为diff环境配置。另外,事实上,您的CI和开发服务器是完全不同的(linux和osx)。与其担心这一点,我认为您应该专注于创建一种可复制的方法来正确设置CI。你可以通过编写自己的rake任务来实现这一点。我同意你的说法,我唯一想避免的是将依赖平台的gems(autotest growl)放在公共环境(即开发)中,因为如果我需要在具有开发环境的暂存服务器上运行应用程序(以显示演示或概念验证)它在Linux上不起作用。我在我的ci上使用,我想保持它的简单,所以我想让我在ci上的运行步骤像
bundle安装一样简单;耙规格;rake Cumber
。我对这个问题进行了大量搜索,目前没有解决方案。所以我认为你的回答是正确的。
group :development do
  gem "autotest-growl"
  gem "autotest-fsevents"
end