EnvMock

CI Gem Version Maintainability codecov Patreon

Mock your ENVs.

Install

Add the following code on your Gemfile and run bundle install:

gem 'env_mock'

Usage

ENV['DATABASE_USERNAME'] = 'wbotelhos'

ENV['DATABASE_USERNAME']
=> 'root'

ENV['TAX_CENTS']
=> nil

ENV['UDP']
=> nil

EnvMock.mock(DATABASE_USERNAME: 'wbotelhos', TAX_CENTS: 700, 'udp' => true) do
  ENV['DATABASE_USERNAME'] # .to_sym is called for all keys
  => 'wbotelhos'

  ENV['TAX_CENTS']
  => '700' # `.to_s` is called for all values

  ENV['UDP'] # .upcase is called for all keys
  => 'true'
end

ENV['DATABASE_USERNAME']
=> 'root'

ENV['TAX_CENTS']
=> nil

ENV['UDP']
=> nil