Railsでテストする方法
■テストスクリプトを用いる
test/models/member_test.rbのコメントアウトを外して、
ruby bin/rake db:migrate RAILS_ENV=test
というコマンドを実行。テーブルが加えられるのデータベースは、テスト用になる。
ruby bin/rake test test/models/member_test.rb
というコマンドを実行するとエラーが発生。
Gemfile内の、
group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' end
を
group :development do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' end
に変更した。
■FactroyGirlを用いる
参考リンク
Railsのテストを実行しようとすると`Web Console is activated in the test environment`と怒られた話 - Blank?=False