chefspec 8.0.1 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +16 -9
- data/Rakefile +60 -52
- data/chefspec.gemspec +20 -20
- data/lib/chefspec.rb +29 -29
- data/lib/chefspec/api.rb +15 -13
- data/lib/chefspec/api/core.rb +3 -3
- data/lib/chefspec/api/described.rb +3 -5
- data/lib/chefspec/api/include_any_recipe.rb +24 -0
- data/lib/chefspec/api/stubs.rb +2 -2
- data/lib/chefspec/api/stubs_for.rb +23 -20
- data/lib/chefspec/berkshelf.rb +4 -4
- data/lib/chefspec/cacher.rb +2 -2
- data/lib/chefspec/coverage.rb +35 -40
- data/lib/chefspec/coverage/filters.rb +18 -15
- data/lib/chefspec/deprecations.rb +3 -3
- data/lib/chefspec/errors.rb +7 -7
- data/lib/chefspec/expect_exception.rb +2 -1
- data/lib/chefspec/extensions.rb +14 -13
- data/lib/chefspec/extensions/chef/client.rb +3 -3
- data/lib/chefspec/extensions/chef/conditional.rb +2 -1
- data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +5 -4
- data/lib/chefspec/extensions/chef/cookbook_loader.rb +1 -0
- data/lib/chefspec/extensions/chef/cookbook_uploader.rb +1 -1
- data/lib/chefspec/extensions/chef/data_query.rb +3 -3
- data/lib/chefspec/extensions/chef/lwrp_base.rb +1 -0
- data/lib/chefspec/extensions/chef/provider.rb +8 -5
- data/lib/chefspec/extensions/chef/resource.rb +18 -12
- data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
- data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +21 -1
- data/lib/chefspec/extensions/chef/securable.rb +1 -1
- data/lib/chefspec/extensions/ohai/system.rb +11 -0
- data/lib/chefspec/file_cache_path_proxy.rb +3 -3
- data/lib/chefspec/formatter.rb +15 -3
- data/lib/chefspec/librarian.rb +7 -6
- data/lib/chefspec/matchers.rb +9 -8
- data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
- data/lib/chefspec/matchers/include_any_recipe_matcher.rb +51 -0
- data/lib/chefspec/matchers/include_recipe_matcher.rb +1 -1
- data/lib/chefspec/matchers/link_to_matcher.rb +2 -2
- data/lib/chefspec/matchers/notifications_matcher.rb +5 -4
- data/lib/chefspec/matchers/render_file_matcher.rb +3 -3
- data/lib/chefspec/matchers/resource_matcher.rb +18 -16
- data/lib/chefspec/mixins/normalize.rb +1 -1
- data/lib/chefspec/policyfile.rb +6 -6
- data/lib/chefspec/renderer.rb +4 -4
- data/lib/chefspec/rspec.rb +1 -1
- data/lib/chefspec/runner.rb +1 -1
- data/lib/chefspec/server.rb +1 -1
- data/lib/chefspec/server_methods.rb +8 -8
- data/lib/chefspec/server_runner.rb +10 -10
- data/lib/chefspec/solo_runner.rb +26 -24
- data/lib/chefspec/stubs/command_registry.rb +1 -1
- data/lib/chefspec/stubs/command_stub.rb +1 -1
- data/lib/chefspec/stubs/data_bag_item_registry.rb +1 -1
- data/lib/chefspec/stubs/data_bag_item_stub.rb +1 -1
- data/lib/chefspec/stubs/data_bag_registry.rb +1 -1
- data/lib/chefspec/stubs/data_bag_stub.rb +1 -1
- data/lib/chefspec/stubs/registry.rb +1 -1
- data/lib/chefspec/stubs/search_registry.rb +2 -2
- data/lib/chefspec/stubs/search_stub.rb +2 -2
- data/lib/chefspec/util.rb +7 -7
- data/lib/chefspec/version.rb +1 -1
- data/lib/chefspec/zero_server.rb +4 -4
- data/spec/spec_helper.rb +3 -4
- data/spec/support/hash.rb +3 -3
- data/spec/unit/cacher_spec.rb +17 -17
- data/spec/unit/coverage/filters_spec.rb +16 -16
- data/spec/unit/deprecations_spec.rb +8 -9
- data/spec/unit/errors_spec.rb +15 -15
- data/spec/unit/expect_exception_spec.rb +9 -9
- data/spec/unit/macros_spec.rb +50 -50
- data/spec/unit/matchers/do_nothing_matcher.rb +1 -1
- data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +52 -0
- data/spec/unit/matchers/include_recipe_matcher_spec.rb +15 -15
- data/spec/unit/matchers/link_to_matcher_spec.rb +18 -18
- data/spec/unit/matchers/notifications_matcher_spec.rb +15 -16
- data/spec/unit/matchers/render_file_matcher_spec.rb +26 -26
- data/spec/unit/matchers/resource_matcher_spec.rb +1 -1
- data/spec/unit/matchers/state_attrs_matcher_spec.rb +24 -24
- data/spec/unit/matchers/subscribes_matcher_spec.rb +27 -29
- data/spec/unit/renderer_spec.rb +36 -36
- data/spec/unit/server_runner_spec.rb +6 -6
- data/spec/unit/solo_runner_spec.rb +69 -69
- data/spec/unit/stubs/command_registry_spec.rb +11 -11
- data/spec/unit/stubs/command_stub_spec.rb +26 -26
- data/spec/unit/stubs/data_bag_item_registry_spec.rb +17 -17
- data/spec/unit/stubs/data_bag_item_stub_spec.rb +14 -14
- data/spec/unit/stubs/data_bag_registry_spec.rb +16 -16
- data/spec/unit/stubs/data_bag_stub_spec.rb +13 -13
- data/spec/unit/stubs/registry_spec.rb +9 -9
- data/spec/unit/stubs/search_registry_spec.rb +17 -17
- data/spec/unit/stubs/search_stub_spec.rb +14 -14
- data/spec/unit/stubs/stub_spec.rb +22 -22
- metadata +16 -12
@@ -1,5 +1,5 @@
|
|
1
1
|
require "chef/version"
|
2
|
-
require "mixlib/shellout"
|
2
|
+
require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
|
3
3
|
|
4
4
|
module ChefSpec
|
5
5
|
module API
|
@@ -35,7 +35,7 @@ module ChefSpec
|
|
35
35
|
before do
|
36
36
|
allow(StubsFor).to receive(:setup_stubs_for) do |object, type|
|
37
37
|
type_stubs = _chefspec_stubs_for_registry[type]
|
38
|
-
resource_object = object.
|
38
|
+
resource_object = object.respond_to?(:new_resource) ? object.new_resource : object
|
39
39
|
stubs = type_stubs[nil] + type_stubs[resource_object.resource_name.to_s] + type_stubs[resource_object.to_s]
|
40
40
|
stubs.each do |stub|
|
41
41
|
instance_exec(object, &stub)
|
@@ -56,23 +56,25 @@ module ChefSpec
|
|
56
56
|
# expect(subject.some_method).to eq "asdf"
|
57
57
|
# end
|
58
58
|
# @param target [String, nil] Resource name to inject, or nil for all resources.
|
59
|
-
# @param
|
59
|
+
# @param current_value [Boolean] If true, also register stubs for current_value objects on the same target.
|
60
60
|
# @param block [Proc] A block taking the resource object as a parameter.
|
61
61
|
# @return [void]
|
62
|
-
def stubs_for_resource(target=nil, current_resource: true, &block)
|
62
|
+
def stubs_for_resource(target = nil, current_value: true, current_resource: true, &block)
|
63
|
+
current_value = false unless current_resource
|
63
64
|
_chefspec_stubs_for_registry[:resource][target] << block
|
64
|
-
|
65
|
+
stubs_for_current_value(target, &block) if current_value
|
65
66
|
end
|
66
67
|
|
67
|
-
# Register stubs for
|
68
|
+
# Register stubs for current_value objects.
|
68
69
|
#
|
69
70
|
# @see #stubs_for_resource
|
70
71
|
# @param target [String, nil] Resource name to inject, or nil for all resources.
|
71
72
|
# @param block [Proc] A block taking the resource object as a parameter.
|
72
73
|
# @return [void]
|
73
|
-
def
|
74
|
-
_chefspec_stubs_for_registry[:
|
74
|
+
def stubs_for_current_value(target = nil, &block)
|
75
|
+
_chefspec_stubs_for_registry[:current_value][target] << block
|
75
76
|
end
|
77
|
+
alias_method :stubs_for_current_resource, :stubs_for_current_value
|
76
78
|
|
77
79
|
# Register stubs for provider objects.
|
78
80
|
#
|
@@ -80,15 +82,15 @@ module ChefSpec
|
|
80
82
|
# @param target [String, nil] Resource name to inject, or nil for all providers.
|
81
83
|
# @param block [Proc] A block taking the resource object as a parameter.
|
82
84
|
# @return [void]
|
83
|
-
def stubs_for_provider(target=nil, &block)
|
85
|
+
def stubs_for_provider(target = nil, &block)
|
84
86
|
_chefspec_stubs_for_registry[:provider][target] << block
|
85
87
|
end
|
86
88
|
|
87
|
-
def receive_shell_out(*cmd, stdout:
|
89
|
+
def receive_shell_out(*cmd, stdout: "", stderr: "", exitstatus: 0, **opts)
|
88
90
|
# Ruby does not allow constructing an actual exitstatus object from Ruby code. Really.
|
89
91
|
fake_exitstatus = double(exitstatus: exitstatus)
|
90
92
|
fake_cmd = Mixlib::ShellOut.new(*cmd)
|
91
|
-
fake_cmd.define_singleton_method(:run_command) {
|
93
|
+
fake_cmd.define_singleton_method(:run_command) {} # Do nothing, just in case.
|
92
94
|
# Inject our canned data.
|
93
95
|
fake_cmd.instance_exec do
|
94
96
|
@stdout = stdout
|
@@ -97,24 +99,25 @@ module ChefSpec
|
|
97
99
|
end
|
98
100
|
# On newer Chef, we can intercept using the new, better shell_out_compact hook point.
|
99
101
|
shell_out_method ||= if HAS_SHELLOUT_COMPACTED.satisfied_by?(Gem::Version.create(Chef::VERSION))
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
:shell_out_compacted
|
103
|
+
else
|
104
|
+
:shell_out
|
105
|
+
end
|
104
106
|
with_args = cmd + (opts.empty? ? [any_args] : [hash_including(opts)])
|
105
107
|
receive(shell_out_method).with(*with_args).and_return(fake_cmd)
|
106
108
|
end
|
107
109
|
|
108
110
|
module ClassMethods
|
109
111
|
# (see StubsFor#stubs_for_resource)
|
110
|
-
def stubs_for_resource(*args, &block)
|
111
|
-
before { stubs_for_resource(*args, &block) }
|
112
|
+
def stubs_for_resource(*args, **kwargs, &block)
|
113
|
+
before { stubs_for_resource(*args, **kwargs, &block) }
|
112
114
|
end
|
113
115
|
|
114
|
-
# (see StubsFor#
|
115
|
-
def
|
116
|
-
before {
|
116
|
+
# (see StubsFor#stubs_for_current_value)
|
117
|
+
def stubs_for_current_value(*args, &block)
|
118
|
+
before { stubs_for_current_value(*args, &block) }
|
117
119
|
end
|
120
|
+
alias_method :stubs_for_current_resource, :stubs_for_current_value
|
118
121
|
|
119
122
|
# (see StubsFor#stubs_for_provider)
|
120
123
|
def stubs_for_provider(*args, &block)
|
data/lib/chefspec/berkshelf.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "berkshelf"
|
3
3
|
rescue LoadError
|
4
|
-
raise ChefSpec::Error::GemLoadError.new(gem:
|
4
|
+
raise ChefSpec::Error::GemLoadError.new(gem: "berkshelf", name: "Berkshelf")
|
5
5
|
end
|
6
6
|
|
7
7
|
module ChefSpec
|
@@ -23,14 +23,14 @@ module ChefSpec
|
|
23
23
|
def setup!
|
24
24
|
# Get the list of Berkshelf options
|
25
25
|
opts = RSpec.configuration.berkshelf_options
|
26
|
-
|
26
|
+
unless opts.is_a?(Hash)
|
27
27
|
raise InvalidBerkshelfOptions(value: opts.inspect)
|
28
28
|
end
|
29
29
|
|
30
30
|
berksfile = ::Berkshelf::Berksfile.from_options(opts)
|
31
31
|
|
32
32
|
# Grab a handle to tmpdir, since Berkshelf 2 modifies it a bit
|
33
|
-
tmpdir = File.join(@tmpdir,
|
33
|
+
tmpdir = File.join(@tmpdir, "cookbooks")
|
34
34
|
|
35
35
|
::Berkshelf.ui.mute do
|
36
36
|
if ::Berkshelf::Berksfile.method_defined?(:vendor)
|
data/lib/chefspec/cacher.rb
CHANGED
@@ -42,8 +42,8 @@ module ChefSpec
|
|
42
42
|
location ||= ancestors.first.metadata[:parent_example_group][:location]
|
43
43
|
|
44
44
|
define_method(name) do
|
45
|
-
key = [location, name.to_s].join(
|
46
|
-
unless @@cache.
|
45
|
+
key = [location, name.to_s].join(".")
|
46
|
+
unless @@cache.key?(Thread.current.object_id)
|
47
47
|
ObjectSpace.define_finalizer(Thread.current, FINALIZER)
|
48
48
|
end
|
49
49
|
@@cache[Thread.current.object_id] ||= {}
|
data/lib/chefspec/coverage.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "coverage/filters"
|
2
2
|
|
3
3
|
module ChefSpec
|
4
4
|
class Coverage
|
@@ -30,14 +30,14 @@ module ChefSpec
|
|
30
30
|
@filters = {}
|
31
31
|
@outputs = []
|
32
32
|
add_output do |report|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
|
34
|
+
erb = Erubis::Eruby.new(File.read(@template))
|
35
|
+
puts erb.evaluate(report)
|
36
|
+
rescue NameError => e
|
37
|
+
raise Error::ErbTemplateParseError.new(original_error: e.message)
|
38
|
+
|
39
39
|
end
|
40
|
-
@template = ChefSpec.root.join(
|
40
|
+
@template = ChefSpec.root.join("templates", "coverage", "human.erb")
|
41
41
|
end
|
42
42
|
|
43
43
|
#
|
@@ -63,17 +63,17 @@ module ChefSpec
|
|
63
63
|
def add_filter(filter = nil, &block)
|
64
64
|
id = "#{filter.inspect}/#{block.inspect}".hash
|
65
65
|
|
66
|
-
@filters[id] = if filter.
|
66
|
+
@filters[id] = if filter.is_a?(Filter)
|
67
67
|
filter
|
68
|
-
elsif filter.
|
68
|
+
elsif filter.is_a?(String)
|
69
69
|
StringFilter.new(filter)
|
70
|
-
elsif filter.
|
70
|
+
elsif filter.is_a?(Regexp)
|
71
71
|
RegexpFilter.new(filter)
|
72
72
|
elsif block
|
73
73
|
BlockFilter.new(block)
|
74
74
|
else
|
75
|
-
raise ArgumentError,
|
76
|
-
|
75
|
+
raise ArgumentError, "Please specify either a string, " \
|
76
|
+
"filter, or block to filter source files with!"
|
77
77
|
end
|
78
78
|
|
79
79
|
true
|
@@ -98,18 +98,14 @@ module ChefSpec
|
|
98
98
|
#
|
99
99
|
# @return [true]
|
100
100
|
#
|
101
|
-
def set_template(file =
|
102
|
-
[
|
103
|
-
ChefSpec.root.join(
|
104
|
-
File.expand_path(file, Dir.pwd)
|
105
|
-
].
|
106
|
-
|
107
|
-
@template = temp
|
108
|
-
return
|
109
|
-
end
|
110
|
-
end
|
111
|
-
raise Error::TemplateNotFound.new(path: file)
|
101
|
+
def set_template(file = "human.erb")
|
102
|
+
@template = [
|
103
|
+
ChefSpec.root.join("templates", "coverage", file),
|
104
|
+
File.expand_path(file, Dir.pwd),
|
105
|
+
].find { |f| File.exist?(f) }
|
106
|
+
raise Error::TemplateNotFound.new(path: file) unless @template
|
112
107
|
end
|
108
|
+
|
113
109
|
#
|
114
110
|
# Add a resource to the resource collection. Only new resources are added
|
115
111
|
# and only resources that match the given filter are covered (which is *
|
@@ -129,9 +125,8 @@ module ChefSpec
|
|
129
125
|
# @param [Chef::Resource] resource
|
130
126
|
#
|
131
127
|
def cover!(resource)
|
132
|
-
|
133
|
-
|
134
|
-
end
|
128
|
+
wrapper = find(resource)
|
129
|
+
wrapper.touch! if wrapper
|
135
130
|
end
|
136
131
|
|
137
132
|
#
|
@@ -166,7 +161,7 @@ module ChefSpec
|
|
166
161
|
report = {}.tap do |h|
|
167
162
|
h[:total] = @collection.size
|
168
163
|
h[:touched] = @collection.count { |_, resource| resource.touched? }
|
169
|
-
h[:coverage] = ((h[:touched]/h[:total].to_f)*100).round(2)
|
164
|
+
h[:coverage] = ((h[:touched] / h[:total].to_f) * 100).round(2)
|
170
165
|
end
|
171
166
|
|
172
167
|
report[:untouched_resources] = @collection.collect do |_, resource|
|
@@ -175,7 +170,7 @@ module ChefSpec
|
|
175
170
|
report[:all_resources] = @collection.values
|
176
171
|
|
177
172
|
@outputs.each do |block|
|
178
|
-
|
173
|
+
instance_exec(report, &block)
|
179
174
|
end
|
180
175
|
|
181
176
|
# Ensure we exit correctly (#351)
|
@@ -208,24 +203,24 @@ module ChefSpec
|
|
208
203
|
"source_file" => source_file,
|
209
204
|
"source_line" => source_line,
|
210
205
|
"touched" => touched?,
|
211
|
-
"resource" => to_s
|
206
|
+
"resource" => to_s,
|
212
207
|
}.to_json
|
213
208
|
end
|
214
209
|
|
215
210
|
def source_file
|
216
211
|
@source_file ||= if @resource.source_line
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
212
|
+
shortname(@resource.source_line.split(":").first)
|
213
|
+
else
|
214
|
+
"Unknown"
|
215
|
+
end
|
221
216
|
end
|
222
217
|
|
223
218
|
def source_line
|
224
219
|
@source_line ||= if @resource.source_line
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
220
|
+
@resource.source_line.split(":", 2).last.to_i
|
221
|
+
else
|
222
|
+
"Unknown"
|
223
|
+
end
|
229
224
|
end
|
230
225
|
|
231
226
|
def touch!
|
@@ -241,8 +236,8 @@ module ChefSpec
|
|
241
236
|
def shortname(file)
|
242
237
|
if file.include?(Dir.pwd)
|
243
238
|
file.split(Dir.pwd, 2).last
|
244
|
-
elsif file.include?(
|
245
|
-
file.split(
|
239
|
+
elsif file.include?("cookbooks")
|
240
|
+
file.split("cookbooks/", 2).last
|
246
241
|
else
|
247
242
|
file
|
248
243
|
end
|
@@ -6,7 +6,7 @@ module ChefSpec
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def matches?
|
9
|
-
raise
|
9
|
+
raise "Must override Filter#matches?"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -17,6 +17,7 @@ module ChefSpec
|
|
17
17
|
class RegexpFilter < Filter
|
18
18
|
def matches?(resource)
|
19
19
|
return true if resource.source_line.nil?
|
20
|
+
|
20
21
|
@filter =~ resource.source_line
|
21
22
|
end
|
22
23
|
end
|
@@ -41,6 +42,7 @@ module ChefSpec
|
|
41
42
|
class BlockFilter < Filter
|
42
43
|
def matches?(resource)
|
43
44
|
return true if resource.source_line.nil?
|
45
|
+
|
44
46
|
@filter.call(resource)
|
45
47
|
end
|
46
48
|
end
|
@@ -54,25 +56,26 @@ module ChefSpec
|
|
54
56
|
@berksfile = berksfile
|
55
57
|
|
56
58
|
@metadatas = if berksfile.respond_to?(:dependencies)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
berksfile.dependencies
|
60
|
+
.select(&:metadata?)
|
61
|
+
.map(&:name)
|
62
|
+
else
|
63
|
+
berksfile.sources.collect do |source|
|
64
|
+
location = source.location
|
65
|
+
if location.respond_to?(:metadata?) && location.metadata?
|
66
|
+
source
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end.compact.map(&:name)
|
71
|
+
end
|
70
72
|
end
|
71
73
|
|
72
74
|
def matches?(resource)
|
73
75
|
return true if resource.source_line.nil?
|
76
|
+
|
74
77
|
normalized_source_line = resource.source_line.gsub("\\", "/")
|
75
|
-
normalized_source_line=~ /
|
78
|
+
normalized_source_line =~ %r{cookbooks/(?!#{@metadatas.join('|')})}
|
76
79
|
end
|
77
80
|
end
|
78
81
|
end
|
@@ -7,9 +7,9 @@ module Kernel
|
|
7
7
|
# @param [Array<String>] messages
|
8
8
|
def deprecated(*messages)
|
9
9
|
messages.each do |message|
|
10
|
-
calling_spec = caller.find { |line| line =~ /
|
10
|
+
calling_spec = caller.find { |line| line =~ %r{(/spec)|(_spec\.rb)} }
|
11
11
|
if calling_spec
|
12
|
-
calling_spec =
|
12
|
+
calling_spec = "spec/" + calling_spec.split("/spec/").last
|
13
13
|
warn "[DEPRECATION] #{message} (called from #{calling_spec})"
|
14
14
|
else
|
15
15
|
warn "[DEPRECATION] #{message}"
|
@@ -42,5 +42,5 @@ module ChefSpec
|
|
42
42
|
end
|
43
43
|
|
44
44
|
module ChefSpec::Error
|
45
|
-
class NoConversionError < ChefSpecError;
|
45
|
+
class NoConversionError < ChefSpecError; end
|
46
46
|
end
|
data/lib/chefspec/errors.rb
CHANGED
@@ -2,9 +2,9 @@ module ChefSpec
|
|
2
2
|
module Error
|
3
3
|
class ChefSpecError < StandardError
|
4
4
|
def initialize(options = {})
|
5
|
-
class_name = self.class.to_s.split(
|
5
|
+
class_name = self.class.to_s.split("::").last
|
6
6
|
filename = options.delete(:_template) || Util.underscore(class_name)
|
7
|
-
template = ChefSpec.root.join(
|
7
|
+
template = ChefSpec.root.join("templates", "errors", "#{filename}.erb")
|
8
8
|
|
9
9
|
erb = Erubis::Eruby.new(File.read(template))
|
10
10
|
super erb.evaluate(options)
|
@@ -13,12 +13,12 @@ module ChefSpec
|
|
13
13
|
|
14
14
|
class NotStubbed < ChefSpecError
|
15
15
|
def initialize(options = {})
|
16
|
-
name = self.class.name.to_s.split(
|
17
|
-
type = Util.underscore(name).gsub(
|
18
|
-
klass = Stubs.const_get(name.gsub(
|
19
|
-
stub = klass.new(*options[:args]).and_return(
|
16
|
+
name = self.class.name.to_s.split("::").last
|
17
|
+
type = Util.underscore(name).gsub("_not_stubbed", "")
|
18
|
+
klass = Stubs.const_get(name.gsub("NotStubbed", "") + "Stub")
|
19
|
+
stub = klass.new(*options[:args]).and_return("...").signature
|
20
20
|
|
21
|
-
signature = "#{type}(#{options[:args].map(&:inspect).join(
|
21
|
+
signature = "#{type}(#{options[:args].map(&:inspect).join(", ")})"
|
22
22
|
|
23
23
|
super({
|
24
24
|
type: type,
|
@@ -26,6 +26,7 @@ module ChefSpec
|
|
26
26
|
|
27
27
|
def expected?
|
28
28
|
return false if @matcher.nil?
|
29
|
+
|
29
30
|
exception_matched? && message_matched?
|
30
31
|
end
|
31
32
|
|
@@ -33,7 +34,7 @@ module ChefSpec
|
|
33
34
|
|
34
35
|
def exception_matched?
|
35
36
|
@formatter_exception == @matcher.last_error_for_chefspec ||
|
36
|
-
|
37
|
+
@matcher.last_error_for_chefspec === @formatter_exception
|
37
38
|
end
|
38
39
|
|
39
40
|
def message_matched?
|
data/lib/chefspec/extensions.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rspec"
|
2
2
|
|
3
3
|
module ChefSpec::Extensions
|
4
4
|
module Chef
|
@@ -6,15 +6,16 @@ module ChefSpec::Extensions
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# STOP! DO NOT ALPHABETIZE!
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
require_relative
|
15
|
-
require_relative
|
16
|
-
require_relative
|
17
|
-
require_relative
|
18
|
-
require_relative
|
19
|
-
require_relative
|
20
|
-
require_relative
|
9
|
+
require_relative "extensions/chef/data_query" # must be before Chef::Resource loads
|
10
|
+
require_relative "extensions/chef/resource" # must come before client extensions or anything that winds up loading resources
|
11
|
+
require_relative "extensions/chef/provider"
|
12
|
+
require_relative "extensions/chef/securable"
|
13
|
+
require_relative "extensions/chef/client"
|
14
|
+
require_relative "extensions/chef/conditional"
|
15
|
+
require_relative "extensions/chef/cookbook_uploader"
|
16
|
+
require_relative "extensions/chef/cookbook/gem_installer"
|
17
|
+
require_relative "extensions/chef/lwrp_base"
|
18
|
+
require_relative "extensions/chef/resource/freebsd_package"
|
19
|
+
require_relative "extensions/chef/run_context/cookbook_compiler"
|
20
|
+
require_relative "extensions/chef/cookbook_loader"
|
21
|
+
require_relative "extensions/ohai/system"
|