You should be sure that your test suite is running with RAILS_ENV=test
For RubyMine you can set this up in Run > Edit Configurations.. > Choose test suite you want to run (i.e. spec: project_name) > Environment variables and there add variable mentioned above.