[Ruby] cannot load such file — ci/reporter/rake/rspec

Ruby on Rails で Capistrano でデプロイしたら、bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile の実行で下記のエラーが発生したので、解決方法をメモ。

■ エラーメッセージ

cannot load such file -- ci/reporter/rake/rspec

ci_reporter は development, test 環境のみにインストールする gem なので、Rakefile に LoadError の例外をキャッチするコードを追記して、production 環境でも動くように対応しました。

% cat Rakefile 
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 
require File.expand_path('../config/application', __FILE__)
 
begin
  require 'ci/reporter/rake/rspec'
rescue LoadError
end
 
myapp::Application.load_tasks

以上です。