Project

ice_age

0.1
No release in over 3 years
Freeze your ENVironment for testing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
 Project Readme

IceAge

Gem codecov

Freeze your ENVironment during testing. ENV is reset after each test, making it trivial to maintain test isolation while testing your code with different environment variable values.

Install

gem install ice_age

Usage

require 'ice_age'

describe 'Feature' do
  context 'with new feature enabled' do
    before { ENV['FEATURE_ENABLED'] = 'true' }

    it { expect(ENV['FEATURE_ENABLED']).to eq 'true' }

    # run tests against enabled feature
  end

  # ENV resets
  it { expect(ENV['FEATURE_ENABLED']).to be_nil }

  # run tests when feature is disabled
end

Inglorious Alternatives

before do
  allow(ENV).to receive(:[]).and_call_original
  allow(ENV).to receive(:[]).with('FEATURE_ENABLED').and_return('true')
end


before do
  stub_const('ENV', ENV.to_hash.merge('FEATURE_ENABLED' => 'true'))
end


around do |example|
  ENV['FEATURE_ENABLED'] = 'true'

  example.run

  ENV['FEATURE_ENABLED'] = nil
end


# https://github.com/thoughtbot/climate_control
around do |example|
  ClimateControl.modify FEATURE_ENABLED: 'true' do
    example.run
  end
end


# https://github.com/ljkbennett/stub_env
before do
  stub_env('key', 'value')
end