2011-04-12 75 views
7

在Rails项目我工作我插入RSpec的,黄瓜和自动测试与此Gemfile中(部分)自动测试平台特定的宝石,捆绑

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上,我想启用自动测试,咆哮和自动测试,fsevents宝石,但如果我插入我的~/.autotest那些行

require 'autotest/growl' 
require 'autotest/fsevent' 

然后我需要插入在Gemfile中相应的宝石和一切工作,但它打破建立我的CI服务器(这是在Linux上)上

如何解决这个不维护本地不同的Gemfile和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 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 

所以我对这个问题的最终解决方案是包括在一个给定组平台特定的宝石,说OSX,然后在生产和CI服务器上使用排除捆绑它。

如果使用Capistrano的部署来把这个在您的config.rb

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

回答

0

您可能需要使用组在Gemfile中,是这样的:

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

,并在服务器上使用:$ bundle install --without development

+0

我在我的ci上使用了[这个配置](https://github.com/fabn/rails-jenkins-template),我想保持简单,所以我想继续在ci上运行简单的作为'捆绑安装;耙规格;犁耙黄瓜'。 – Fabio 2011-04-12 13:00:49

+0

我对这个问题进行了大量搜索,目前没有解决方案。所以我会接受你的回答是正确的。 – Fabio 2011-05-28 00:42:59

0

您可以通过采取不同的Gemfile环境(测试,开发,生产)的优势,处理这个问题。

您的本地盒子可以开发,而CI服务器是您的“生产”环境。

考虑到这一点,您可以编辑您的Gemfile以根据环境使用适当的宝石。

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

+0

的'〜/ .autotest'文件是没有问题的,因为它位于我的主目录中,而不是在项目根目录中。问题是它需要两个Gemfile中没有列出的宝石,所以在bundle上下文中需要那些宝石会产生加载错误。我想避免使用其他方法(管理Gemfile中的不同环境)以避免跨配置重复。 – Fabio 2011-04-12 12:20:54

+0

好吧,我更了解你的问题。但是你是否说你不喜欢在你的Gemfile中有不同的“测试,开发,生产”组?因为这正是那些团队的存在。 diff配置diff环境。另外,事实是你的CI和开发服务器是完全不同的(linux vs osx)。与其担心这一点,我认为你应该专注于创建一个可重复的方式来正确设置您的配置项。你可以通过编写你自己的rake任务来做到这一点。 – Dty 2011-04-12 13:14:39

+0

我同意你所说的,唯一我想避免的是将平台依赖的gem(autotest-growl)放在一个通用的环境中(即开发),因为如果我需要在分期中运行应用程序服务器与开发环境(以显示演示或概念证明),它不会在Linux上工作。 – Fabio 2011-04-12 13:29:23