ruby-on-rails – 带捆绑器的自动测试的平台特定宝石

在我正在研究的rails项目中,我使用此Gemfile插入了对rspec,黄瓜和自动测试的支持(部分)
gem 'rspec-rails'
gem 'cucumber-rails'
gem 'autotest-standalone'
gem 'autotest-rails-pure'
gem 'zentest-without-autotest'

但是为了使用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中插入相应的gems,一切正常,但它会破坏我的CI服务器上的构建(在Linux上)

如何在不为本地和CI环境维护不同的Gemfile的情况下解决这个问题?

编辑:

目前我在Gemfile中用这些行解决

if RUBY_PLATFORM.downcase.include?("darwin") # I'm on Mac
  gem 'autotest-fsevent'
  gem 'autotest-growl'
end

它既可以在本地也可以在CI服务器上运行,我不知道它是否会弄乱一些东西,目前它似乎完美无缺.

任何更干净的方式仍然是受欢迎的.

EDIT2:

我切换到群组解决方案.虽然之前的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

所以我对这个问题的最终解决方案是在给定的组中包含特定于平台的gems,比如osx,然后在生产中和CI服务器上使用bundle排除它.

如果你使用capistrano部署把它放在你的config.rb中

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

解决方法

您可能希望在gemfile中使用组,例如:
group :development do
  gem "autotest-growl"
  gem "autotest-fsevents"
end

并在您使用的服务器上:$bundle install – without development

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...