2011-04-12 74 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