ice_age

Freeze your ENVironment for testing.


License
MIT
Install
gem install ice_age -v 0.2.0

Documentation

IceAge

Freeze your ENVironment during testing. Just in case you need to change ENV variables during tests, this library ensures that everything is reset before the next test runs.

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

Gem codecov codebeat badge