How to run Rails console in the test environment and load test_helper.rb? How to run Rails console in the test environment and load test_helper.rb? ruby-on-rails ruby-on-rails

How to run Rails console in the test environment and load test_helper.rb?


For Rails < 3.0

Run script/console --help. You'll notice that the syntax is script/console [environment], which in your case is script/console test.

I'm not sure if you have to require the test helper or if the test environment does that for you, but with that command you should at least be able to boot successfully into the test env.

As a sidenote: It is indeed kind of odd that the various binaries in script/ has different ways of setting the rails environment.

For Rails 3 and 4

Run rails c test. Prepend bundle exec if you need this for the current app environment.

For Rails 5 and 6

Run rails console -e test.


In Rails 3, just do rails console test or rails console production or rails console development (which is the default).


script/console test

Should be all you need.