rspec-puppet 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/rspec-puppet-init +20 -0
- data/lib/rspec-puppet.rb +2 -0
- data/lib/rspec-puppet/example/class_example_group.rb +1 -0
- data/lib/rspec-puppet/example/define_example_group.rb +1 -0
- data/lib/rspec-puppet/example/host_example_group.rb +1 -0
- data/lib/rspec-puppet/matchers/create_generic.rb +32 -2
- data/lib/rspec-puppet/setup.rb +144 -0
- data/rspec-puppet.gemspec +5 -1
- data/spec/classes/boolean_spec.rb +7 -6
- metadata +11 -7
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
require 'rspec-puppet'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
:module_name => nil,
|
10
|
+
}
|
11
|
+
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: rspec-puppet-init [options]"
|
14
|
+
|
15
|
+
opts.on('-n', '--name NAME', 'The name of the module (override autodetection)') do |v|
|
16
|
+
options[:module_name] = v
|
17
|
+
end
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
RSpec::Puppet::Setup.run(options[:module_name])
|
data/lib/rspec-puppet.rb
CHANGED
@@ -2,10 +2,12 @@ require 'puppet'
|
|
2
2
|
require 'rspec'
|
3
3
|
require 'rspec-puppet/matchers'
|
4
4
|
require 'rspec-puppet/example'
|
5
|
+
require 'rspec-puppet/setup'
|
5
6
|
|
6
7
|
RSpec.configure do |c|
|
7
8
|
c.add_setting :module_path, :default => '/etc/puppet/modules'
|
8
9
|
c.add_setting :manifest_dir, :default => nil
|
9
10
|
c.add_setting :manifest, :default => nil
|
10
11
|
c.add_setting :template_dir, :default => nil
|
12
|
+
c.add_setting :config, :default => nil
|
11
13
|
end
|
@@ -12,6 +12,7 @@ module RSpec::Puppet
|
|
12
12
|
Puppet[:manifestdir] = self.respond_to?(:manifest_dir) ? manifest_dir : RSpec.configuration.manifest_dir
|
13
13
|
Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest
|
14
14
|
Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir
|
15
|
+
Puppet[:config] = self.respond_to?(:config) ? config : RSpec.configuration.config
|
15
16
|
|
16
17
|
klass_name = self.class.top_level_description.downcase
|
17
18
|
|
@@ -14,6 +14,7 @@ module RSpec::Puppet
|
|
14
14
|
Puppet[:manifestdir] = self.respond_to?(:manifest_dir) ? manifest_dir : RSpec.configuration.manifest_dir
|
15
15
|
Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest
|
16
16
|
Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir
|
17
|
+
Puppet[:config] = self.respond_to?(:config) ? config : RSpec.configuration.config
|
17
18
|
|
18
19
|
# If we're testing a standalone module (i.e. one that's outside of a
|
19
20
|
# puppet tree), the autoloader won't work, so we need to fudge it a bit.
|
@@ -12,6 +12,7 @@ module RSpec::Puppet
|
|
12
12
|
Puppet[:manifestdir] = self.respond_to?(:manifest_dir) ? manifest_dir : RSpec.configuration.manifest_dir
|
13
13
|
Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest
|
14
14
|
Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir
|
15
|
+
Puppet[:config] = self.respond_to?(:config) ? config : RSpec.configuration.config
|
15
16
|
Puppet[:code] = ""
|
16
17
|
|
17
18
|
nodename = self.class.top_level_description.downcase
|
@@ -17,7 +17,7 @@ module RSpec::Puppet
|
|
17
17
|
|
18
18
|
def without(*args, &block)
|
19
19
|
params = args.shift
|
20
|
-
@expected_undef_params = (@expected_undef_params || []) | params
|
20
|
+
@expected_undef_params = (@expected_undef_params || []) | Array(params)
|
21
21
|
self
|
22
22
|
end
|
23
23
|
|
@@ -50,6 +50,11 @@ module RSpec::Puppet
|
|
50
50
|
ret = false
|
51
51
|
(@errors ||= []) << "#{name.to_s} matching `#{value.inspect}` but its value of `#{rsrc_hsh[name.to_sym].inspect}` does not"
|
52
52
|
end
|
53
|
+
elsif value.kind_of?(Array) then
|
54
|
+
unless rsrc_hsh[name.to_sym].join == value.join
|
55
|
+
ret = false
|
56
|
+
(@errors ||= []) << "#{name.to_s} set to `#{value.inspect}` but it is set to `#{rsrc_hsh[name.to_sym].inspect}` in the catalogue"
|
57
|
+
end
|
53
58
|
else
|
54
59
|
unless rsrc_hsh[name.to_sym].to_s == value.to_s
|
55
60
|
ret = false
|
@@ -81,7 +86,32 @@ module RSpec::Puppet
|
|
81
86
|
end
|
82
87
|
|
83
88
|
def description
|
84
|
-
|
89
|
+
values = []
|
90
|
+
if @expected_params
|
91
|
+
@expected_params.each do |name, value|
|
92
|
+
if value.kind_of?(Regexp)
|
93
|
+
values << "#{name.to_s} matching #{value.inspect}"
|
94
|
+
else
|
95
|
+
values << "#{name.to_s} => #{value.inspect}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if @expected_undef_params
|
101
|
+
@expected_undef_params.each do |name, value|
|
102
|
+
values << "#{name.to_s} undefined"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
unless values.empty?
|
107
|
+
if values.length == 1
|
108
|
+
value_str = " with #{values.first}"
|
109
|
+
else
|
110
|
+
value_str = " with #{values[0..-2].join(", ")} and #{values[-1]}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
"contain #{@referenced_type}[#{@title}]#{value_str}"
|
85
115
|
end
|
86
116
|
|
87
117
|
private
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module RSpec::Puppet
|
5
|
+
class Setup
|
6
|
+
def self.run(module_name=nil)
|
7
|
+
unless is_module_dir?
|
8
|
+
$stderr.puts "Does not appear to be a Puppet module. Aborting"
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
|
12
|
+
if module_name.nil?
|
13
|
+
module_name = get_module_name
|
14
|
+
if module_name.nil?
|
15
|
+
$stderr.puts "Unable to determine module name. Aborting"
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
[
|
21
|
+
'spec',
|
22
|
+
'spec/classes',
|
23
|
+
'spec/defines',
|
24
|
+
'spec/functions',
|
25
|
+
'spec/hosts',
|
26
|
+
'spec/fixtures',
|
27
|
+
'spec/fixtures/manifests',
|
28
|
+
'spec/fixtures/modules',
|
29
|
+
"spec/fixtures/modules/#{module_name}",
|
30
|
+
].each { |dir| safe_mkdir(dir) }
|
31
|
+
|
32
|
+
safe_touch('spec/fixtures/manifests/site.pp')
|
33
|
+
|
34
|
+
['manifests','lib','files','templates'].each do |dir|
|
35
|
+
if File.exist? dir
|
36
|
+
safe_make_symlink("../../../../#{dir}", "spec/fixtures/modules/#{module_name}/#{dir}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
safe_create_spec_helper
|
41
|
+
safe_create_rakefile
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def self.get_module_name
|
46
|
+
p = Puppet::Parser::Lexer.new
|
47
|
+
module_name = nil
|
48
|
+
Dir["manifests/*.pp"].entries.each do |manifest|
|
49
|
+
p.string = File.read(manifest)
|
50
|
+
tokens = p.fullscan
|
51
|
+
i = tokens.index { |token| [:CLASS, :DEFINE].include? token.first }
|
52
|
+
unless i.nil?
|
53
|
+
module_name = tokens[i + 1].last[:value].split('::').first
|
54
|
+
break
|
55
|
+
end
|
56
|
+
end
|
57
|
+
module_name
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.is_module_dir?
|
61
|
+
Dir["*"].entries.include? "manifests"
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.safe_mkdir(dir)
|
65
|
+
if File.exists? dir
|
66
|
+
unless File.directory? dir
|
67
|
+
$stderr.puts "!! #{dir} already exists and is not a directory"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
FileUtils.mkdir dir
|
71
|
+
puts " + #{dir}/"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.safe_touch(file)
|
76
|
+
if File.exists? file
|
77
|
+
unless File.file? file
|
78
|
+
$stderr.puts "!! #{file} already exists and is not a regular file"
|
79
|
+
end
|
80
|
+
else
|
81
|
+
FileUtils.touch file
|
82
|
+
puts " + #{file}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.safe_create_spec_helper
|
87
|
+
content = <<-EOF
|
88
|
+
require 'rspec-puppet'
|
89
|
+
|
90
|
+
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
|
91
|
+
|
92
|
+
RSpec.configure do |c|
|
93
|
+
c.module_path = File.join(fixture_path, 'modules')
|
94
|
+
c.manifest_dir = File.join(fixture_path, 'manifests')
|
95
|
+
end
|
96
|
+
EOF
|
97
|
+
if File.exists? 'spec/spec_helper.rb'
|
98
|
+
old_content = File.read('spec/spec_helper.rb')
|
99
|
+
if old_content != content
|
100
|
+
$stderr.puts "!! spec/spec_helper.rb already exists and differs from template"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
File.open('spec/spec_helper.rb', 'w') do |f|
|
104
|
+
f.puts content
|
105
|
+
end
|
106
|
+
puts ' + spec/spec_helper.rb'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.safe_make_symlink(source, target)
|
111
|
+
if File.exists? target
|
112
|
+
unless File.symlink? target
|
113
|
+
$stderr.puts "!! #{file} already exists and is not a symlink"
|
114
|
+
end
|
115
|
+
else
|
116
|
+
FileUtils.ln_s(source, target)
|
117
|
+
puts " + #{target}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.safe_create_rakefile
|
122
|
+
content = <<-EOF
|
123
|
+
require 'rake'
|
124
|
+
|
125
|
+
require 'rspec/core/rake_task'
|
126
|
+
|
127
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
128
|
+
t.pattern = 'spec/*/*_spec.rb'
|
129
|
+
end
|
130
|
+
EOF
|
131
|
+
if File.exists? 'Rakefile'
|
132
|
+
old_content = File.read('Rakefile')
|
133
|
+
if old_content != content
|
134
|
+
$stderr.puts "!! Rakefile already exists and differs from template"
|
135
|
+
end
|
136
|
+
else
|
137
|
+
File.open('Rakefile', 'w') do |f|
|
138
|
+
f.puts content
|
139
|
+
end
|
140
|
+
puts ' + Rakefile'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/rspec-puppet.gemspec
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rspec-puppet'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.3'
|
4
4
|
s.homepage = 'https://github.com/rodjek/rspec-puppet/'
|
5
5
|
s.summary = 'RSpec tests for your Puppet manifests'
|
6
6
|
s.description = 'RSpec tests for your Puppet manifests'
|
7
7
|
|
8
|
+
s.executables = ['rspec-puppet-init']
|
9
|
+
|
8
10
|
s.files = [
|
11
|
+
'bin/rspec-puppet-init',
|
9
12
|
'lib/rspec-puppet/example/class_example_group.rb',
|
10
13
|
'lib/rspec-puppet/example/define_example_group.rb',
|
11
14
|
'lib/rspec-puppet/example/function_example_group.rb',
|
@@ -16,6 +19,7 @@ Gem::Specification.new do |s|
|
|
16
19
|
'lib/rspec-puppet/matchers/include_class.rb',
|
17
20
|
'lib/rspec-puppet/matchers/run.rb',
|
18
21
|
'lib/rspec-puppet/matchers.rb',
|
22
|
+
'lib/rspec-puppet/setup.rb',
|
19
23
|
'lib/rspec-puppet/support.rb',
|
20
24
|
'lib/rspec-puppet.rb',
|
21
25
|
'LICENSE',
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if Puppet::PUPPETVERSION !~ /0\.2/
|
4
|
+
describe 'boolean' do
|
5
|
+
let(:title) { 'bool.testing' }
|
6
|
+
let(:params) { { :bool => false } }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
it { should create_notify("bool testing")\
|
9
|
+
.with_message("This will print when \$bool is false.") }
|
10
|
+
end
|
10
11
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Sharpe
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-07 00:00:00 -07:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
@@ -33,13 +34,14 @@ dependencies:
|
|
33
34
|
version_requirements: *id001
|
34
35
|
description: RSpec tests for your Puppet manifests
|
35
36
|
email: tim@sharpe.id.au
|
36
|
-
executables:
|
37
|
-
|
37
|
+
executables:
|
38
|
+
- rspec-puppet-init
|
38
39
|
extensions: []
|
39
40
|
|
40
41
|
extra_rdoc_files: []
|
41
42
|
|
42
43
|
files:
|
44
|
+
- bin/rspec-puppet-init
|
43
45
|
- lib/rspec-puppet/example/class_example_group.rb
|
44
46
|
- lib/rspec-puppet/example/define_example_group.rb
|
45
47
|
- lib/rspec-puppet/example/function_example_group.rb
|
@@ -50,6 +52,7 @@ files:
|
|
50
52
|
- lib/rspec-puppet/matchers/include_class.rb
|
51
53
|
- lib/rspec-puppet/matchers/run.rb
|
52
54
|
- lib/rspec-puppet/matchers.rb
|
55
|
+
- lib/rspec-puppet/setup.rb
|
53
56
|
- lib/rspec-puppet/support.rb
|
54
57
|
- lib/rspec-puppet.rb
|
55
58
|
- LICENSE
|
@@ -68,6 +71,7 @@ files:
|
|
68
71
|
- spec/fixtures/modules/sysctl/manifests/init.pp
|
69
72
|
- spec/functions/split_spec.rb
|
70
73
|
- spec/spec_helper.rb
|
74
|
+
has_rdoc: true
|
71
75
|
homepage: https://github.com/rodjek/rspec-puppet/
|
72
76
|
licenses: []
|
73
77
|
|
@@ -97,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
101
|
requirements: []
|
98
102
|
|
99
103
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.6.2
|
101
105
|
signing_key:
|
102
106
|
specification_version: 3
|
103
107
|
summary: RSpec tests for your Puppet manifests
|