Sha256: 1f9ecb1d834ad63763c1f0a7494ed1c811846bc2358f17f2af2316bf07bf9775

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../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

12 entries across 12 versions & 1 rubygems

Version Path
puppet-2.6.18 spec/unit/util/execution_spec.rb
puppet-2.6.17 spec/unit/util/execution_spec.rb
puppet-2.6.16 spec/unit/util/execution_spec.rb
puppet-2.6.15 spec/unit/util/execution_spec.rb
puppet-2.6.14 spec/unit/util/execution_spec.rb
puppet-2.6.13 spec/unit/util/execution_spec.rb
puppet-2.6.12 spec/unit/util/execution_spec.rb
puppet-2.6.11 spec/unit/util/execution_spec.rb
puppet-2.6.10 spec/unit/util/execution_spec.rb
puppet-2.6.9 spec/unit/util/execution_spec.rb
puppet-2.6.8 spec/unit/util/execution_spec.rb
puppet-2.6.7 spec/unit/util/execution_spec.rb