Module: EnvTestHelpers
- Defined in:
- lib/env_test_helpers.rb,
lib/env_test_helpers/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#mock_env_vars(vars) ⇒ Object
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 goes here end end.
-
#with_env_vars(vars) ⇒ Object
it ‘does something with the FOO environment variable’ do with_env_vars ‘FOO’ => ‘bar’ do # logic that depends upon ENV goes here end end.
Instance Method Details
#mock_env_vars(vars) ⇒ Object
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
26 27 28 29 30 |
# File 'lib/env_test_helpers.rb', line 26 def mock_env_vars(vars) vars.each do |k, v| allow(ENV).to receive(:[]).with(k).and_return(v) end end |
#with_env_vars(vars) ⇒ Object
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
9 10 11 12 13 14 15 16 17 |
# File 'lib/env_test_helpers.rb', line 9 def with_env_vars(vars) original = ENV.to_hash vars.each { |k, v| ENV[k] = v } begin yield ensure ENV.replace(original) end end |