Cyril Duchon-Doris Cyril Duchon-Doris - 7 months ago 11
Ruby Question

Rspec - where is the extra configuration for test environment?

I am using the default

test
for different purposes and I have decided to make a specific
rspec
environment configuration for running the test suite.

However, I discovered that upon changing to
ENV["RAILS_ENV"] ||= rspec
in my
rails_helper.rb
file, suddenly a LOT of things are going wrong, constants are not being loaded (FactoryGirl, DatabaseCleaner, etc. throw
uninitialized constant
errors)

My question is, where is the code that loads those guys in test environment ? Since I am planning to use this stage for other purposes than running automatic tests, I'm afraid this "out of nowhere" added configuration might not work well with what I am planning to do.

Answer

If you are getting uninitialized constant errors for FactoryGirl, DatabaseCleaner etc, you most likely included them to test group in your Gemfile.

You should move them to rspec group, eg:

# Gemfile

group :rspec do
  gem 'factory_girl_rails', '~> 4.0'
  gem 'faker'
end
Comments