summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
authorKen Barber <ken@bob.sh>2011-08-05 08:52:00 +0100
committerKen Barber <ken@bob.sh>2011-08-05 10:31:46 +0100
commitaa27fc76c7d5fa090ea1d47027856c3e70c6ae8f (patch)
treedc9a4ae93fc7345d719de29d956f6488c1b69005 /spec/spec_helper.rb
parent07d0eca31780bba76f2283ce83f944473ce8fe00 (diff)
parent1b73a66fc67af0e33fa41aacf50654d4a7a4903c (diff)
downloadpuppet-stdlib-aa27fc76c7d5fa090ea1d47027856c3e70c6ae8f.tar.gz
puppet-stdlib-aa27fc76c7d5fa090ea1d47027856c3e70c6ae8f.tar.bz2
(#8797) Merge puppetlabs-functions into puppetlabs-stdlib
It was decided that maintaining puppetlabs-functions and puppetlabs-stdlib was duplication as both are trying to achieve the same goal. This patch provides a merge of the puppetlabs-functions into the puppetlabs-stdlib repository, with history preservation. The following conflicts were found and resolved: * LICENSE file from functions was used as it aligns with ASL usage instructions and contains relevant copyright information: http://www.apache.org/licenses/LICENSE-2.0.html * Used spec_helper.rb from functions - this is what Puppet core uses and doesn't break tests. * Merged .gitignore and spec.opts options.
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb84
1 files changed, 72 insertions, 12 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a4aeeae..fdc04bc 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,18 +1,78 @@
-require 'pathname'
-dir = Pathname.new(__FILE__).parent
-$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
+dir = File.expand_path(File.dirname(__FILE__))
+$LOAD_PATH.unshift File.join(dir, 'lib')
+
+p dir
+
+# Don't want puppet getting the command line arguments for rake or autotest
+ARGV.clear
-require 'mocha'
require 'puppet'
-gem 'rspec', '=1.2.9'
-require 'spec/autorun'
+require 'mocha'
+gem 'rspec', '>=2.0.0'
+require 'rspec/expectations'
-Spec::Runner.configure do |config|
- config.mock_with :mocha
+# So everyone else doesn't have to include this base constant.
+module PuppetSpec
+ FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
end
-# We need this because the RAL uses 'should' as a method. This
-# allows us the same behaviour but with a different method name.
-class Object
- alias :must :should
+require 'pathname'
+require 'tmpdir'
+
+require 'puppet_spec/verbose'
+require 'puppet_spec/files'
+require 'puppet_spec/fixtures'
+require 'puppet_spec/matchers'
+require 'monkey_patches/alias_should_to_must'
+require 'monkey_patches/publicize_methods'
+
+Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour|
+ require behaviour.relative_path_from(Pathname.new(dir))
+end
+
+RSpec.configure do |config|
+ include PuppetSpec::Fixtures
+
+ config.mock_with :mocha
+
+ 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"
+
+ # Avoid opening ports to the outside world
+ Puppet.settings[:bindaddress] = "127.0.0.1"
+
+ @logs = []
+ Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs))
+
+ @log_level = Puppet::Util::Log.level
+ end
+
+ config.after :each do
+ Puppet.settings.clear
+ Puppet::Node::Environment.clear
+ Puppet::Util::Storage.clear
+ Puppet::Util::ExecutionStub.reset
+
+ PuppetSpec::Files.cleanup
+
+ @logs.clear
+ Puppet::Util::Log.close_all
+ Puppet::Util::Log.level = @log_level
+
+ GC.enable
+ end
end