nanakondor
nanakondor

Reputation: 745

Is it possible to change Rails ENV in ActionDispatch::IntegrationTest?

ENV variable values are set in config/application.yml in a rails app. is it possible to change only for specific test case in ActionDispatch::IntegrationTest? Something like this:

class DummyTest < ActionDispatch::IntegrationTest
  context '...' do
    it '...' do
      ENV['API_URL'] = ...
    end
  end
end

I have tried this but it doesn't seem to change anything. Thanks

Upvotes: 0

Views: 200

Answers (1)

brcebn
brcebn

Reputation: 1722

I think you've missed creating-rails-environments of the configuration on the Rails documentation. 😉

This should solve your issue without monkey patching anything on your specs.

I would also suggest to use dotenv gem which help you with environment variables. In your case you'll have at least those files:

  • .env.development
  • .env.test

If you really want to update a value for a specific test, I would suggest to stub it like suggested here

Upvotes: 1

Related Questions