私が取り組んでいる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'
次に、対応するgemをGemfileに挿入する必要があり、すべてが機能しますが、CIサーバー(Linux上)でビルドが壊れます。
ローカル環境とCI環境で異なるGemfileを維持せずにこれを解決するにはどうすればよいですか?
編集:
今のところ、Gemfileのこれらの行で解決しました
if RUBY_PLATFORM.downcase.include?("darwin") # I'm on Mac
gem 'autotest-fsevent'
gem 'autotest-growl'
end
ローカルとCIサーバーの両方で機能しますが、何かが混乱しているかどうかはわかりません。現時点では問題なく機能しているようです。
それを行うためのよりクリーンな方法はまだ歓迎されています。
EDIT2:
グループソリューションに切り替えました。以前のモンキーパッチは開発と継続的インテグレーションの両方で非常にうまく機能しますが、デプロイメントに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サーバーでバンドルを使用して除外することです。
capistranoを使用してデプロイする場合は、これをconfig.rb
set :bundle_without, [:development, :test, :osx]
# capistrano bundler task
require "bundler/capistrano"