chefspec 0.7.0 → 0.8.0
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/lib/chefspec/chef_runner.rb
CHANGED
@@ -10,10 +10,10 @@ module ChefSpec
|
|
10
10
|
# The main entry point for running recipes within RSpec.
|
11
11
|
class ChefRunner
|
12
12
|
|
13
|
-
@step_into = []
|
14
13
|
@resources = []
|
15
14
|
|
16
15
|
attr_accessor :resources
|
16
|
+
attr_reader :step_into
|
17
17
|
attr_reader :run_context
|
18
18
|
attr_reader :node
|
19
19
|
|
@@ -24,16 +24,17 @@ module ChefSpec
|
|
24
24
|
# @option options [Symbol] :log_level The log level to use (default is :warn)
|
25
25
|
# @yield [node] Configuration block for Chef::Node
|
26
26
|
def initialize(options={})
|
27
|
-
defaults = {:cookbook_path => default_cookbook_path, :log_level => :warn, :dry_run => false}
|
27
|
+
defaults = {:cookbook_path => default_cookbook_path, :log_level => :warn, :dry_run => false, :step_into => []}
|
28
28
|
options = {:cookbook_path => options} unless options.respond_to?(:to_hash) # backwards-compatibility
|
29
29
|
options = defaults.merge(options)
|
30
30
|
|
31
31
|
the_runner = self
|
32
32
|
@resources = []
|
33
|
+
@step_into = options[:step_into]
|
33
34
|
@do_dry_run = options[:dry_run]
|
34
35
|
|
35
36
|
Chef::Resource.class_eval do
|
36
|
-
alias :old_run_action :run_action
|
37
|
+
alias :old_run_action :run_action unless method_defined?(:old_run_action)
|
37
38
|
|
38
39
|
if self.class.methods.include?(:class_variable_set)
|
39
40
|
self.class_variable_set :@@runner, the_runner
|
@@ -41,13 +42,27 @@ module ChefSpec
|
|
41
42
|
@@runner = the_runner
|
42
43
|
end
|
43
44
|
|
44
|
-
def run_action(
|
45
|
-
|
46
|
-
if self.class.methods.include?(:class_variable_get)
|
47
|
-
self.class.class_variable_get(:@@runner)
|
45
|
+
def run_action(*args)
|
46
|
+
action = args.first
|
47
|
+
runner = if self.class.methods.include?(:class_variable_get)
|
48
|
+
self.class.class_variable_get(:@@runner)
|
48
49
|
else
|
49
|
-
@@runner
|
50
|
+
@@runner
|
51
|
+
end
|
52
|
+
|
53
|
+
if runner.step_into.include?(self.resource_name.to_s)
|
54
|
+
# Ignore not_if / only_if guards
|
55
|
+
if self.only_if.is_a?(Array) # 0.10.x
|
56
|
+
self.instance_eval { @not_if = []; @only_if = [] }
|
57
|
+
else # 0.9.x
|
58
|
+
self.only_if { true }
|
59
|
+
self.not_if { false }
|
60
|
+
end
|
61
|
+
self.old_run_action(action)
|
50
62
|
end
|
63
|
+
|
64
|
+
Chef::Log.info("Processing #{self} action #{action} (#{defined_at})") if self.respond_to? :defined_at
|
65
|
+
runner.resources << self
|
51
66
|
end
|
52
67
|
end
|
53
68
|
|
@@ -60,6 +75,7 @@ module ChefSpec
|
|
60
75
|
Chef::Log.level(options[:log_level])
|
61
76
|
@client = Chef::Client.new
|
62
77
|
fake_ohai(@client.ohai)
|
78
|
+
@client.load_node if @client.respond_to?(:load_node) # chef >= 10.14.0
|
63
79
|
@node = @client.build_node
|
64
80
|
if block_given?
|
65
81
|
yield @node
|
@@ -170,7 +186,7 @@ module ChefSpec
|
|
170
186
|
#
|
171
187
|
# @return [String] The path to the cookbooks directory
|
172
188
|
def default_cookbook_path
|
173
|
-
Pathname.new(File.join(caller(2).first.split(':').slice(0..-3).join(':'), '..', '..', '..')).cleanpath
|
189
|
+
Pathname.new(File.join(caller(2).first.split(':').slice(0..-3).join(':'), '..', '..', '..')).cleanpath.to_s
|
174
190
|
end
|
175
191
|
|
176
192
|
# Find the resource with the declared type and name
|
@@ -41,13 +41,15 @@ def render(template, node)
|
|
41
41
|
# Duplicates functionality in the Chef Template provider
|
42
42
|
context = {}; context.merge!(template.variables)
|
43
43
|
context[:node] = node
|
44
|
-
Erubis::Eruby.new(IO.read(template_path(template))).evaluate(context)
|
44
|
+
Erubis::Eruby.new(IO.read(template_path(template, node))).evaluate(context)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Given a template, return the path on disk.
|
48
48
|
#
|
49
49
|
# @param [Chef::Resource::Template] template The template
|
50
50
|
# @return [String] The path on disk
|
51
|
-
def template_path(template)
|
52
|
-
|
51
|
+
def template_path(template, node)
|
52
|
+
cookbook_name = template.cookbook || template.cookbook_name
|
53
|
+
cookbook = node.cookbook_collection[cookbook_name]
|
54
|
+
cookbook.preferred_filename_on_disk_location(node, :templates, template.source, template.path)
|
53
55
|
end
|
@@ -11,9 +11,10 @@ class Chef
|
|
11
11
|
# @param [String] filename File to load as a LWRP
|
12
12
|
# @param [Chef::RunContext] run_context Context of a Chef Run
|
13
13
|
# @return [Chef::Provider] the created provider
|
14
|
-
def build_from_file(
|
14
|
+
def build_from_file(*args)
|
15
|
+
cookbook_name, filename = args[0,2]
|
15
16
|
remove_existing_lwrp(convert_to_class_name(filename_to_qualified_string(cookbook_name, filename)))
|
16
|
-
old_build_from_file(
|
17
|
+
old_build_from_file(*args)
|
17
18
|
end
|
18
19
|
|
19
20
|
# Remove any existing Chef provider or resource with the specified name.
|
data/lib/chefspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash: -
|
115
|
+
hash: -1887236234485155709
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
@@ -121,12 +121,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash: -
|
124
|
+
hash: -1887236234485155709
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
127
|
rubygems_version: 1.8.19
|
128
128
|
signing_key:
|
129
129
|
specification_version: 3
|
130
|
-
summary: chefspec-0.
|
130
|
+
summary: chefspec-0.8.0
|
131
131
|
test_files: []
|
132
132
|
has_rdoc:
|