Sha256: 3cbef3e58086b2ad2eaf436e7d290032555c3f1ee36d79d9f706f792728c1424

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

require "env_test_helpers/version"

module EnvTestHelpers
  # it 'does something with the FOO environment variable' do
  #   with_env_vars 'FOO' => 'bar' do
  #     # logic that depends upon ENV['FOO'] goes here
  #   end
  # end
  def with_env_vars(vars)
    original = ENV.to_hash
    vars.each { |k, v| ENV[k] = v }
    begin
      yield
    ensure
      ENV.replace(original)
    end
  end
  # describe Thing do
  #   before(:all) do
  #     mock_env_vars('FOO' => 'bar')
  #   end
  #   it 'does something with the FOO environment variable' do
  #     # logic that depends upon ENV['FOO'] goes here
  #   end
  # end
  def mock_env_vars(vars)
    vars.each do |k, v|
      allow(ENV).to receive(:[]).with(k).and_return(v)
    end
  end
end

if defined? RSpec
  RSpec.configure do |c|
    c.include EnvTestHelpers
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
env_test_helpers-0.0.2 lib/env_test_helpers.rb