###発生している問題・エラーメッセージ
Rails4 アプリケーションにおいて test-unit および test-unit-rails を使ったユニットテストを記述しようとしていますが、Gemfile において
ruby
1group :test do 2 gem 'test-unit-rails' 3end
のように test-unit-rails
を記述すると、rake db:migrate RAILS_ENV=test
を実行した際、 rake aborted となり失敗します。
bash
1$ rake db:migrate RAILS_ENV=test 2rake aborted! 3NameError: uninitialized constant ActiveSupport::Testing::ConstantLookup 4/path/to/rails-project-dir/config/environment.rb:5:in `<top (required)>' 5Tasks: TOP => db:migrate:reset => db:migrate => environment 6(See full trace by running task with --trace)
同様の現象は rake db:create RAILS_ENV=test
や rake db:migrate:reset RAILS_ENV=test
など、 RAILS_ENV に test がセットされた場合のデータベースに関係する rake task において現出するようです。
その場合、 Gemfile から test-unit-rails
をコメントアウトすれば問題なく実行できます。
また test-unit-rails
が記述されていても rake test
によるテストは問題なく実施できます。
bash
1$ bundle exec rake test 2Loaded suite /path/to/users-home/.rbenv/versions/2.2.3/bin/rake 3Started 4.. 5 6Finished in 0.032617 seconds. 7---------------------------------------------------------------------------------------------------------------------------------------- 82 tests, 4 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 9100% passed 10---------------------------------------------------------------------------------------------------------------------------------------- 1161.32 tests/s, 122.64 assertions/s
###実現したいこと
Gemfile に test-unit-rails
が指定されている状態でも、rake db:migrate RAILS_ENV=test
などの rake task が実行できるようにしたい。
###該当のソースコード
Gemfile (抜粋)
Ruby
1ruby '2.2.3' 2# ... 3gem 'rails', '4.2.4' 4gem 'mysql2', '~> 0.3.13' 5# ... 6group :test do 7 gem 'test-unit' 8 gem 'test-unit-rails', '~> 1.0.4' 9end
###補足情報(言語/FW/ツール等のバージョンなど)
Mac OS X El Capitan (10.11.6)
Ruby 2.2.3p173
rails 4.2.4
test-unit 3.2.3
test-unit-rails 1.0.4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。