Skip to content

Commit

Permalink
Merge pull request puppetlabs#549 from cprice-puppet/cleanup/master/r…
Browse files Browse the repository at this point in the history
…uby-185-execution-spec-failures

More fixes / cleanup for 1.8.5
  • Loading branch information
pcarlisle committed Mar 1, 2012
2 parents 196c85f + 9b62607 commit 372c398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
8 changes: 2 additions & 6 deletions spec/unit/type/yumrepo_spec.rb
Expand Up @@ -4,6 +4,7 @@


describe Puppet::Type.type(:yumrepo) do
include PuppetSpec::Files

describe "When validating attributes" do

Expand Down Expand Up @@ -88,7 +89,7 @@ def create_data_files()


before(:each) do
@yumdir = Dir.mktmpdir("yumrepo_spec_tmpdir")
@yumdir = tmpdir("yumrepo_spec_tmpdir")
@yumconf = File.join(@yumdir, "yum.conf")
File.open(@yumconf, "w") do |f|
f.print "[main]\nreposdir=#{@yumdir} /no/such/dir\n"
Expand All @@ -99,11 +100,6 @@ def create_data_files()
Puppet::Type.type(:yumrepo).inifile = nil
end

after(:each) do
FileUtils.rm_rf(@yumdir)
end



it "should be able to create a valid config file" do
values = {
Expand Down
16 changes: 4 additions & 12 deletions spec/unit/util/execution_spec.rb
Expand Up @@ -20,14 +20,6 @@ def call_exec_windows(command, arguments, stdin, stdout, stderr)
Puppet::Util::Execution.send(:execute_windows, command, arguments, stdin, stdout, stderr)
end

# utility method for cloning the ENV object. Because it is not ACTUALLY a Hash instance,
# we can't use the built-in #clone method, and because Ruby 1.8.5 doesn't support some of
# the newer constructors for the Hash object, this slightly hacky syntax was the best I
# could come up with. At least it's isolated to one line of code :)
def clone_env()
ENV.inject(Hash.new) {|result,entry| result[entry[0]] = entry[1] ; result }
end


describe "execution methods" do
let(:pid) { 5501 }
Expand Down Expand Up @@ -66,7 +58,7 @@ def stub_process_wait(exitstatus)
# there is a danger here that ENV will be modified by exec_posix. Normally it would only affect the ENV
# of a forked process, but here, we're stubbing Kernel.fork, so the method has the ability to override the
# "real" ENV. To guard against this, we'll capture a snapshot of ENV before each test.
@saved_env = clone_env
@saved_env = ENV.to_hash

# Now, we're going to effectively "mock" the magic ruby 'ENV' variable by creating a local definition of it
# inside of the module we're testing.
Expand All @@ -79,7 +71,7 @@ def stub_process_wait(exitstatus)
Puppet::Util::Execution.send(:remove_const, :ENV)

# capture the current environment and make sure it's the same as it was before the test
cur_env = clone_env
cur_env = ENV.to_hash

# we will get some fairly useless output if we just use the raw == operator on the hashes here, so we'll
# be a bit more explicit and laborious in the name of making the error more useful...
Expand Down Expand Up @@ -295,12 +287,12 @@ def stub_process_wait(exitstatus)
# allow the method to override the "real" ENV. This shouldn't be a problem for these tests because they are
# not stubbing Kernel.fork, but, better safe than sorry... so, to guard against this, we'll capture a snapshot
# of ENV before each test.
@saved_env = clone_env
@saved_env = ENV.to_hash
end

after :each do
# capture the current environment and make sure it's the same as it was before the test
cur_env = clone_env
cur_env = ENV.to_hash
# we will get some fairly useless output if we just use the raw == operator on the hashes here, so we'll
# be a bit more explicit and laborious in the name of making the error more useful...
@saved_env.each_pair { |key,val| cur_env[key].should == val }
Expand Down

0 comments on commit 372c398

Please sign in to comment.