I've written versions of an RSpec helper several times for modifying ENV in specs. Here's one:

https://gist.github.com/soulcutter/b54e6e83c0a9a0dca1ff1ff9ffde2a4e

I shy away from the climate_control gem because a whole 'nother dependency for this seems meh - but go ahead and poke holes in my opinion/implementation

#ruby #rspec

with_env helper for RSpec

with_env helper for RSpec. GitHub Gist: instantly share code, notes, and snippets.

Gist

@soulcutter I didn't know about climate_control. Seems like the perfect example of a dependency to never put into your project since it does something so narrow and basic.

I just do it manually: https://gist.github.com/davetron5000/f0a1d07d82543ec166a6a9e184ed2465

But if there were to be a helper, something like yours as part of the app makes more sense than yet another gem.

In Brut I've set it up so that access to ENV is exactly in one place (a centralized config which is reset at the start of each test, so you can just change it).

foo.spec.rb

GitHub Gist: instantly share code, notes, and snippets.

Gist