Railsのテストを実行しようとすると`Web Console is activated in the test environment`と怒られた話
Railsのテストをを実行しようとrails test
とターミナルに打ったらこんな感じのメッセージが出てきて怒られました。
Web Console is activated in the test environment, which is usually a mistake. To ensure it's only activated in development mode, move it to the development group of your Gemfile: gem 'web-console', group: :development If you still want to run it the test environment (and know what you are doing), put this in your Rails application configuration: config.web_console.development_only = false
解決方法
メッセージに書いてあるとおり、Gemfile
でweb-consoleの宣言を開発環境のみ使えるように書き換えます。
Gemfile
<省略> group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'pry-byebug' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end
↓
<省略> group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'pry-byebug' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' end
そもそもweb-consoleってどんなGem?
このWeb-Console,デフォルトで入るGemなのでどんなGemなのか知らなかったので調べてみた。
エラー画面の時に下に出てくるコンソールがWeb-Consoleみたい。
リポジトリはここ。
github.com
上の解説ページではdevelopment
とtest
環境で動く、とあるけど、Github
のreadmeを見ると、
Why I'm getting an undefined method web_console?
Make sure you configuration lives in config/environments/development.rb.
web_consoleが未定義のメソッドと怒られるけどなんで?という質問に、環境がdevelopment
か確認してね、と回答されているので、基本的にdevelopment
オンリーのようです。
エラーメッセージを見ると、config.web_console.development_only = false
と設定すれば、他の環境でも使えそうな感じですが・・・コレはまた後で試してみよう。