1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
require 'r10k/util/exec_env'
describe R10K::Util::ExecEnv do
describe "withenv" do
it "adds the keys to the environment during the block" do
val = nil
described_class.withenv('VAL' => 'something') do
val = ENV['VAL']
end
expect(val).to eq 'something'
end
it "doesn't modify values that were not modified by the passed hash" do
origpath = ENV['PATH']
path = nil
described_class.withenv('VAL' => 'something') do
path = ENV['PATH']
end
expect(path).to eq origpath
end
it "removes new values after the block" do
val = nil
described_class.withenv('VAL' => 'something') { }
expect(ENV['VAL']).to be_nil
end
it "restores old values after the block" do
path = ENV['PATH']
described_class.withenv('PATH' => '/usr/bin') { }
expect(ENV['PATH']).to eq path
end
end
describe "reset" do
after { ENV.delete('VAL') }
it "replaces environment keys with the specified keys" do
ENV['VAL'] = 'hi'
newenv = ENV.to_hash
newenv['VAL'] = 'bye'
described_class.reset(newenv)
expect(ENV['VAL']).to eq 'bye'
end
it "removes any keys that were not provided" do
env = ENV.to_hash
ENV['VAL'] = 'hi'
described_class.reset(env)
expect(ENV['VAL']).to be_nil
end
end
end
|