Search code examples
ruby-on-railsrubypostgresqldockerruby-on-rails-7

Rspec on Docker with database_cleaner causes remote URL error: RemoteDatabaseUrl


I'm working in Docker, trying to run bundle exec rspec ./spec/services/something/something_spec.rb and I am getting this error

DatabaseCleaner::Safeguard::Error::RemoteDatabaseUrl:
ENV['DATABASE_URL'] is set to a remote URL

Tried a couple of thing but so far nothing was helping


Solution

  • My initial around was to just temporarily comment out DatabaseCleaner use in spec/rails_helper.rb so I could run the test locally in development environment but that wasn't great.

    Then I after reading for a while I found a better solution, tried this

      config.before(:suite) do
        DatabaseCleaner.allow_remote_database_url = true
      end
    

    And it worked. Hope that helps!