Sha256: d8046a60b50e5645719fc3b13247059e9f339f928571dd2ea4b0f4c298f406c7

Contents?: true

Size: 1.43 KB

Versions: 35

Compression:

Stored size: 1.43 KB

Contents

#!/usr/bin/env rspec
require 'spec_helper'

describe Puppet::Util::Execution do
  include Puppet::Util::Execution
  describe "#withenv" do
    before :each do
      @original_path = ENV["PATH"]
      @new_env = {:PATH => "/some/bogus/path"}
    end

    it "should change environment variables within the block then reset environment variables to their original values" do
      withenv @new_env do
        ENV["PATH"].should == "/some/bogus/path"
      end
      ENV["PATH"].should == @original_path
    end

    it "should reset environment variables to their original values even if the block fails" do
      begin
        withenv @new_env do
          ENV["PATH"].should == "/some/bogus/path"
          raise "This is a failure"
        end
      rescue
      end
      ENV["PATH"].should == @original_path
    end

    it "should reset environment variables even when they are set twice" do
      # Setting Path & Environment parameters in Exec type can cause weirdness
      @new_env["PATH"] = "/someother/bogus/path"
      withenv @new_env do
        # When assigning duplicate keys, can't guarantee order of evaluation
        ENV["PATH"].should =~ /\/some.*\/bogus\/path/
      end
      ENV["PATH"].should == @original_path
    end

    it "should remove any new environment variables after the block ends" do
      @new_env[:FOO] = "bar"
      withenv @new_env do
        ENV["FOO"].should == "bar"
      end
      ENV["FOO"].should == nil
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/util/execution_spec.rb
puppet-2.7.25 spec/unit/util/execution_spec.rb
puppet-2.7.24 spec/unit/util/execution_spec.rb
puppet-2.7.23 spec/unit/util/execution_spec.rb
puppet-2.7.22 spec/unit/util/execution_spec.rb
puppet-2.7.21 spec/unit/util/execution_spec.rb
puppet-2.7.20 spec/unit/util/execution_spec.rb
puppet-2.7.20.rc1 spec/unit/util/execution_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/execution_spec.rb
puppet-2.7.19 spec/unit/util/execution_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/execution_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_spec.rb
puppet-2.7.18 spec/unit/util/execution_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/util/execution_spec.rb
puppet-2.7.17 spec/unit/util/execution_spec.rb
puppet-2.7.16 spec/unit/util/execution_spec.rb
puppet-2.7.14 spec/unit/util/execution_spec.rb
puppet-2.7.13 spec/unit/util/execution_spec.rb