From 82194ca7e7c6fdf45db121a360e4dc125a8273b5 Mon Sep 17 00:00:00 2001 From: cprice Date: Tue, 27 Mar 2012 10:38:38 -0700 Subject: (#13439) refactor spec helper for compatibility with both puppet 2.7 and master --- spec/spec_helper.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 87aac34..d6837a9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -65,22 +65,14 @@ RSpec.configure do |config| config.before :each do GC.disable - # these globals are set by Application - $puppet_application_mode = nil - $puppet_application_name = nil # REVISIT: I think this conceals other bad tests, but I don't have time to # fully diagnose those right now. When you read this, please come tell me # I suck for letting this float. --daniel 2011-04-21 Signal.stubs(:trap) - # Set the confdir and vardir to gibberish so that tests - # have to be correctly mocked. - Puppet[:confdir] = "/dev/null" - Puppet[:vardir] = "/dev/null" + Puppet.settings.send(:initialize_everything_for_tests) - # Avoid opening ports to the outside world - Puppet.settings[:bindaddress] = "127.0.0.1" @logs = [] Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) @@ -89,7 +81,7 @@ RSpec.configure do |config| end config.after :each do - Puppet.settings.clear + Puppet.settings.send(:clear_everything_for_tests) Puppet::Node::Environment.clear Puppet::Util::Storage.clear Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? "ExecutionStub" -- cgit v1.2.3 From 665610baaf052a4b7b1c73682b9183ea743f2593 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 29 Mar 2012 16:52:15 -0700 Subject: (#13439) Fix test failures with Puppet 2.6.x Without this patch the spec_helper sends a message named initialize_everything_for_tests to Puppet.settings. This is a problem because Puppet 2.6.x does not have this method, only Puppet 2.7.x and Puppet master have this method at this time and we're getting false positive test failures. This patch fixes the problem by looking before we leap. We test if the private method exists before calling it. This works with Ruby 1.8.5 and onwards and Puppet 2.6, 2.7 and master. This should fix all of the failures I've caused in Jenkins today. --- spec/spec_helper.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d6837a9..d0b493e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,7 +71,12 @@ RSpec.configure do |config| # I suck for letting this float. --daniel 2011-04-21 Signal.stubs(:trap) - Puppet.settings.send(:initialize_everything_for_tests) + # We're using send because this is a private method to communicate it + # should only be used for tests. We're testing if it's defined to work + # with Puppet 2.6.x which does not have the method. + if Puppet.settings.private_methods.include? "initialize_everything_for_tests" + Puppet.settings.send(:initialize_everything_for_tests) + end @logs = [] @@ -81,7 +86,12 @@ RSpec.configure do |config| end config.after :each do - Puppet.settings.send(:clear_everything_for_tests) + # We're using send because this is a private method to communicate it + # should only be used for tests. We're testing if it's defined to work + # with Puppet 2.6.x which does not have the method at all. + if Puppet.settings.private_methods.include? "clear_everything_for_tests" + Puppet.settings.send(:clear_everything_for_tests) + end Puppet::Node::Environment.clear Puppet::Util::Storage.clear Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? "ExecutionStub" -- cgit v1.2.3