Skip to content

wbotelhos/env_mock

Repository files navigation

EnvMock

CI Gem Version Maintainability codecov Sponsor

Mock your ENVs.

Install

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

gem 'env_mock'

Usage

ENV['DATABASE_USERNAME'] = 'root'

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_s 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