I have been running Rspec recently but realised it was completely deleting my development database. I believe the cause of this is the failure of setting 'RAILS_ENV' at the beginning of 'rails_helper.rb' and therefore database cleaner is clearing the development db as well as the test db. Unsure if this is actually what is happening.
In order to combat the issue of
[1] RAILS_ENV
=> nil
[2] ENV['RAILS_ENV']
=> nil
I decided to set ENV['RAILS_ENV'] at the beginning of the file but this appears to break everything
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
after some digging, it's a call to 'Bundle.require(*Rails.groups)' that actually breaks and the response is
[1] Bundle.require(*Rails.groups)
=> NameError: uninitialized constant FactoryBotFactory::BaseFactory
I am calling this prior to loading the application due to an issue of setting constants throughout the application rather than using "ENV['SOMETHING']". This works fine locally and in production and even works for rspec... but not if I set 'ENV['RAILS_ENV']'
application.rb
Bundler.require(*Rails.groups)
Dotenv::Railtie.load unless Rails.env.production?
require_relative 'constants'
module MyApp
class Application < Rails::Application