|
1 |
| -dir = File.expand_path(File.dirname(__FILE__)) |
2 |
| -$LOAD_PATH.unshift File.join(dir, 'lib') |
3 |
| - |
4 |
| -# Don't want puppet getting the command line arguments for rake or autotest |
5 |
| -ARGV.clear |
6 |
| - |
7 |
| -require 'puppet' |
8 |
| -require 'mocha' |
9 |
| -gem 'rspec', '>=2.0.0' |
10 |
| -require 'rspec/expectations' |
11 |
| - |
12 |
| -# So everyone else doesn't have to include this base constant. |
13 |
| -module PuppetSpec |
14 |
| - FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) |
15 |
| -end |
16 |
| - |
17 |
| -require 'pathname' |
18 |
| -require 'tmpdir' |
19 |
| - |
20 |
| -require 'puppet_spec/verbose' |
21 |
| -require 'puppet_spec/files' |
22 |
| -require 'puppet_spec/fixtures' |
23 |
| -require 'puppet_spec/matchers' |
24 |
| -require 'monkey_patches/alias_should_to_must' |
25 |
| -require 'monkey_patches/publicize_methods' |
26 |
| - |
27 |
| -Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour| |
28 |
| - require behaviour.relative_path_from(Pathname.new(dir)) |
29 |
| -end |
30 |
| - |
31 |
| -RSpec.configure do |config| |
32 |
| - include PuppetSpec::Fixtures |
33 |
| - |
34 |
| - config.mock_with :mocha |
35 |
| - |
36 |
| - config.before :each do |
37 |
| - GC.disable |
38 |
| - |
39 |
| - # We need to preserve the current state of all our indirection cache and |
40 |
| - # terminus classes. This is pretty important, because changes to these |
41 |
| - # are global and lead to order dependencies in our testing. |
42 |
| - # |
43 |
| - # We go direct to the implementation because there is no safe, sane public |
44 |
| - # API to manage restoration of these to their default values. This |
45 |
| - # should, once the value is proved, be moved to a standard API on the |
46 |
| - # indirector. |
47 |
| - # |
48 |
| - # To make things worse, a number of the tests stub parts of the |
49 |
| - # indirector. These stubs have very specific expectations that what |
50 |
| - # little of the public API we could use is, well, likely to explode |
51 |
| - # randomly in some tests. So, direct access. --daniel 2011-08-30 |
52 |
| - $saved_indirection_state = {} |
53 |
| - indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections) |
54 |
| - indirections.each do |indirector| |
55 |
| - $saved_indirection_state[indirector.name] = { |
56 |
| - :@terminus_class => indirector.instance_variable_get(:@terminus_class), |
57 |
| - :@cache_class => indirector.instance_variable_get(:@cache_class) |
58 |
| - } |
59 |
| - end |
60 |
| - |
61 |
| - # these globals are set by Application |
62 |
| - $puppet_application_mode = nil |
63 |
| - $puppet_application_name = nil |
64 |
| - |
65 |
| - # REVISIT: I think this conceals other bad tests, but I don't have time to |
66 |
| - # fully diagnose those right now. When you read this, please come tell me |
67 |
| - # I suck for letting this float. --daniel 2011-04-21 |
68 |
| - Signal.stubs(:trap) |
69 |
| - |
70 |
| - # Set the confdir and vardir to gibberish so that tests |
71 |
| - # have to be correctly mocked. |
72 |
| - Puppet[:confdir] = "/dev/null" |
73 |
| - Puppet[:vardir] = "/dev/null" |
74 |
| - |
75 |
| - # Avoid opening ports to the outside world |
76 |
| - Puppet.settings[:bindaddress] = "127.0.0.1" |
77 |
| - |
78 |
| - @logs = [] |
79 |
| - Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) |
80 |
| - |
81 |
| - @log_level = Puppet::Util::Log.level |
82 |
| - end |
83 |
| - |
84 |
| - config.after :each do |
85 |
| - Puppet.settings.clear |
86 |
| - Puppet::Node::Environment.clear |
87 |
| - Puppet::Util::Storage.clear |
88 |
| - Puppet::Util::ExecutionStub.reset |
89 |
| - |
90 |
| - PuppetSpec::Files.cleanup |
91 |
| - |
92 |
| - @logs.clear |
93 |
| - Puppet::Util::Log.close_all |
94 |
| - Puppet::Util::Log.level = @log_level |
95 |
| - |
96 |
| - # Restore the indirector configuration. See before hook. |
97 |
| - indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections) |
98 |
| - indirections.each do |indirector| |
99 |
| - $saved_indirection_state.fetch(indirector.name, {}).each do |variable, value| |
100 |
| - indirector.instance_variable_set(variable, value) |
101 |
| - end |
102 |
| - end |
103 |
| - $saved_indirection_state = nil |
104 |
| - |
105 |
| - GC.enable |
106 |
| - end |
107 |
| -end |
| 1 | +require 'rubygems' |
| 2 | +require 'puppetlabs_spec_helper/module_spec_helper' |
0 commit comments