Skip to content

Commit 5de7366

Browse files
committed
Migrate to puppetlabs_spec_helper
The puppetlabs_spec_helper gem is designed for puppet modules and makes it easier to write spec tests. All the spec/lib and spec/monkey_patches are not needed anymore. For more info visit https://github.com/puppetlabs/puppetlabs_spec_helper
1 parent 8da9aff commit 5de7366

File tree

9 files changed

+6
-305
lines changed

9 files changed

+6
-305
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'rubygems'
2+
require 'puppetlabs_spec_helper/rake_tasks'

spec/integration/provider/oratab/parsed_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
require 'puppet/file_bucket/dipper'
55

66
describe Puppet::Type.type(:oratab).provider(:parsed), '(integration)' do
7-
include PuppetSpec::Files
7+
include PuppetlabsSpec::Files
88

99
before :each do
1010
described_class.stubs(:suitable?).returns true
1111
Puppet::Type.type(:oratab).stubs(:defaultprovider).returns described_class
1212

13-
@fake_oratab = tmpfile('oratab')
13+
@fake_oratab = tmpfilename('oratab')
1414
FileUtils.cp(my_fixture('input'), @fake_oratab)
1515
described_class.stubs(:default_target).returns @fake_oratab
1616

spec/lib/puppet_spec/files.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.

spec/lib/puppet_spec/fixtures.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

spec/lib/puppet_spec/matchers.rb

Lines changed: 0 additions & 87 deletions
This file was deleted.

spec/lib/puppet_spec/verbose.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/monkey_patches/alias_should_to_must.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/monkey_patches/publicize_methods.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/spec_helper.rb

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,2 @@
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

Comments
 (0)