Sha256: 140bac91419f07c23387c464892328460c366cc487b0a1b4efc66f1f3ffbce9b

Contents?: true

Size: 1.33 KB

Versions: 69

Compression:

Stored size: 1.33 KB

Contents

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

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
r10k-3.15.0 spec/unit/util/exec_env_spec.rb
akerl-r10k-3.14.2.1 spec/unit/util/exec_env_spec.rb
r10k-3.14.2 spec/unit/util/exec_env_spec.rb
r10k-3.14.1 spec/unit/util/exec_env_spec.rb
r10k-3.14.0 spec/unit/util/exec_env_spec.rb
r10k-3.13.0 spec/unit/util/exec_env_spec.rb
r10k-3.12.1 spec/unit/util/exec_env_spec.rb
r10k-3.12.0 spec/unit/util/exec_env_spec.rb
r10k-3.11.0 spec/unit/util/exec_env_spec.rb
r10k-3.10.0 spec/unit/util/exec_env_spec.rb
r10k-3.9.3 spec/unit/util/exec_env_spec.rb
r10k-3.9.2 spec/unit/util/exec_env_spec.rb
r10k-3.9.1 spec/unit/util/exec_env_spec.rb
r10k-3.9.0 spec/unit/util/exec_env_spec.rb
r10k-3.8.0 spec/unit/util/exec_env_spec.rb
r10k-3.7.0 spec/unit/util/exec_env_spec.rb
r10k-3.6.0 spec/unit/util/exec_env_spec.rb
r10k-2.6.9 spec/unit/util/exec_env_spec.rb
r10k-3.5.2 spec/unit/util/exec_env_spec.rb
r10k-3.5.1 spec/unit/util/exec_env_spec.rb