chefspec 9.2.0 → 9.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -9
  3. data/Rakefile +60 -52
  4. data/chefspec.gemspec +20 -20
  5. data/lib/chefspec/api/core.rb +3 -3
  6. data/lib/chefspec/api/described.rb +3 -5
  7. data/lib/chefspec/api/stubs.rb +2 -2
  8. data/lib/chefspec/api/stubs_for.rb +13 -13
  9. data/lib/chefspec/api.rb +14 -14
  10. data/lib/chefspec/berkshelf.rb +4 -4
  11. data/lib/chefspec/cacher.rb +2 -2
  12. data/lib/chefspec/coverage/filters.rb +18 -15
  13. data/lib/chefspec/coverage.rb +35 -40
  14. data/lib/chefspec/deprecations.rb +3 -3
  15. data/lib/chefspec/errors.rb +7 -7
  16. data/lib/chefspec/expect_exception.rb +2 -1
  17. data/lib/chefspec/extensions/chef/client.rb +3 -3
  18. data/lib/chefspec/extensions/chef/conditional.rb +2 -1
  19. data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +5 -4
  20. data/lib/chefspec/extensions/chef/cookbook_loader.rb +1 -0
  21. data/lib/chefspec/extensions/chef/cookbook_uploader.rb +1 -1
  22. data/lib/chefspec/extensions/chef/data_query.rb +3 -3
  23. data/lib/chefspec/extensions/chef/lwrp_base.rb +1 -0
  24. data/lib/chefspec/extensions/chef/provider.rb +8 -5
  25. data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
  26. data/lib/chefspec/extensions/chef/resource.rb +14 -9
  27. data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +12 -1
  28. data/lib/chefspec/extensions/chef/securable.rb +1 -1
  29. data/lib/chefspec/extensions/ohai/system.rb +1 -1
  30. data/lib/chefspec/extensions.rb +14 -14
  31. data/lib/chefspec/file_cache_path_proxy.rb +3 -3
  32. data/lib/chefspec/formatter.rb +3 -3
  33. data/lib/chefspec/librarian.rb +7 -6
  34. data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
  35. data/lib/chefspec/matchers/include_any_recipe_matcher.rb +4 -4
  36. data/lib/chefspec/matchers/include_recipe_matcher.rb +1 -1
  37. data/lib/chefspec/matchers/link_to_matcher.rb +2 -2
  38. data/lib/chefspec/matchers/notifications_matcher.rb +5 -4
  39. data/lib/chefspec/matchers/render_file_matcher.rb +3 -3
  40. data/lib/chefspec/matchers/resource_matcher.rb +18 -16
  41. data/lib/chefspec/matchers.rb +9 -9
  42. data/lib/chefspec/mixins/normalize.rb +1 -1
  43. data/lib/chefspec/policyfile.rb +10 -7
  44. data/lib/chefspec/renderer.rb +4 -4
  45. data/lib/chefspec/rspec.rb +1 -1
  46. data/lib/chefspec/server.rb +1 -1
  47. data/lib/chefspec/server_methods.rb +8 -8
  48. data/lib/chefspec/server_runner.rb +10 -10
  49. data/lib/chefspec/solo_runner.rb +27 -25
  50. data/lib/chefspec/stubs/command_registry.rb +1 -1
  51. data/lib/chefspec/stubs/command_stub.rb +1 -1
  52. data/lib/chefspec/stubs/data_bag_item_registry.rb +1 -1
  53. data/lib/chefspec/stubs/data_bag_item_stub.rb +1 -1
  54. data/lib/chefspec/stubs/data_bag_registry.rb +1 -1
  55. data/lib/chefspec/stubs/data_bag_stub.rb +1 -1
  56. data/lib/chefspec/stubs/registry.rb +1 -1
  57. data/lib/chefspec/stubs/search_registry.rb +2 -2
  58. data/lib/chefspec/stubs/search_stub.rb +2 -2
  59. data/lib/chefspec/util.rb +7 -7
  60. data/lib/chefspec/version.rb +1 -1
  61. data/lib/chefspec/zero_server.rb +4 -4
  62. data/lib/chefspec.rb +29 -29
  63. data/spec/spec_helper.rb +3 -4
  64. data/spec/support/hash.rb +4 -4
  65. data/spec/unit/cacher_spec.rb +17 -17
  66. data/spec/unit/coverage/filters_spec.rb +16 -16
  67. data/spec/unit/deprecations_spec.rb +8 -9
  68. data/spec/unit/errors_spec.rb +15 -15
  69. data/spec/unit/expect_exception_spec.rb +9 -9
  70. data/spec/unit/macros_spec.rb +50 -50
  71. data/spec/unit/matchers/do_nothing_matcher.rb +1 -1
  72. data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +23 -23
  73. data/spec/unit/matchers/include_recipe_matcher_spec.rb +15 -15
  74. data/spec/unit/matchers/link_to_matcher_spec.rb +18 -18
  75. data/spec/unit/matchers/notifications_matcher_spec.rb +15 -16
  76. data/spec/unit/matchers/render_file_matcher_spec.rb +26 -26
  77. data/spec/unit/matchers/resource_matcher_spec.rb +1 -1
  78. data/spec/unit/matchers/state_attrs_matcher_spec.rb +24 -24
  79. data/spec/unit/matchers/subscribes_matcher_spec.rb +27 -29
  80. data/spec/unit/renderer_spec.rb +36 -36
  81. data/spec/unit/server_runner_spec.rb +6 -6
  82. data/spec/unit/solo_runner_spec.rb +69 -69
  83. data/spec/unit/stubs/command_registry_spec.rb +11 -11
  84. data/spec/unit/stubs/command_stub_spec.rb +26 -26
  85. data/spec/unit/stubs/data_bag_item_registry_spec.rb +17 -17
  86. data/spec/unit/stubs/data_bag_item_stub_spec.rb +14 -14
  87. data/spec/unit/stubs/data_bag_registry_spec.rb +16 -16
  88. data/spec/unit/stubs/data_bag_stub_spec.rb +13 -13
  89. data/spec/unit/stubs/registry_spec.rb +9 -9
  90. data/spec/unit/stubs/search_registry_spec.rb +17 -17
  91. data/spec/unit/stubs/search_stub_spec.rb +14 -14
  92. data/spec/unit/stubs/stub_spec.rb +22 -22
  93. metadata +6 -8
  94. data/lib/chefspec/extensions/.DS_Store +0 -0
  95. data/lib/chefspec/extensions/chef/.DS_Store +0 -0
@@ -1,4 +1,4 @@
1
- require_relative 'coverage/filters'
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
- begin
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
- end
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('templates', 'coverage', 'human.erb')
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.kind_of?(Filter)
66
+ @filters[id] = if filter.is_a?(Filter)
67
67
  filter
68
- elsif filter.kind_of?(String)
68
+ elsif filter.is_a?(String)
69
69
  StringFilter.new(filter)
70
- elsif filter.kind_of?(Regexp)
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, 'Please specify either a string, ' \
76
- 'filter, or block to filter source files with!'
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 = 'human.erb')
102
- [
103
- ChefSpec.root.join('templates', 'coverage', file),
104
- File.expand_path(file, Dir.pwd)
105
- ].each do |temp|
106
- if File.exist?(temp)
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
- if wrapper = find(resource)
133
- wrapper.touch!
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
- self.instance_exec(report, &block)
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
- shortname(@resource.source_line.split(':').first)
218
- else
219
- 'Unknown'
220
- end
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
- @resource.source_line.split(':', 2).last.to_i
226
- else
227
- 'Unknown'
228
- end
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?('cookbooks')
245
- file.split('cookbooks/', 2).last
239
+ elsif file.include?("cookbooks")
240
+ file.split("cookbooks/", 2).last
246
241
  else
247
242
  file
248
243
  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 =~ /(\/spec)|(_spec\.rb)/ }
10
+ calling_spec = caller.find { |line| line =~ %r{(/spec)|(_spec\.rb)} }
11
11
  if calling_spec
12
- calling_spec = 'spec/' + calling_spec.split('/spec/').last
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; end
45
+ class NoConversionError < ChefSpecError; end
46
46
  end
@@ -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('::').last
5
+ class_name = self.class.to_s.split("::").last
6
6
  filename = options.delete(:_template) || Util.underscore(class_name)
7
- template = ChefSpec.root.join('templates', 'errors', "#{filename}.erb")
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('::').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
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
- @matcher.last_error_for_chefspec === @formatter_exception
37
+ @matcher.last_error_for_chefspec === @formatter_exception
37
38
  end
38
39
 
39
40
  def message_matched?
@@ -1,11 +1,11 @@
1
1
  # Force loading Chef Config to fix a bad dependency tree. See
2
2
  # https://github.com/opscode/chef/issues/2703 for more information.
3
- require 'chef/config'
3
+ require "chef/config"
4
4
 
5
5
  # Providers has to be included before client... probably a weird
6
6
  # include missing in Chef-land, but we can make sure we get it right anyway.
7
- require 'chef/providers'
8
- require 'chef/client'
7
+ require "chef/providers"
8
+ require "chef/client"
9
9
 
10
10
  # @private
11
11
  Chef::Client.prepend(Module.new do
@@ -1,9 +1,10 @@
1
- require 'chef/resource/conditional'
1
+ require "chef/resource/conditional"
2
2
 
3
3
  Chef::Resource::Conditional.prepend(Module.new do
4
4
  # @see Chef::Resource::Conditional#evaluate_command
5
5
  def evaluate_command
6
6
  return super unless $CHEFSPEC_MODE
7
+
7
8
  stub = ChefSpec::Stubs::CommandRegistry.stub_for(@command)
8
9
 
9
10
  if stub.nil?
@@ -1,9 +1,10 @@
1
- require 'chef/cookbook/gem_installer'
1
+ require "chef/cookbook/gem_installer"
2
2
 
3
3
  Chef::Cookbook::GemInstaller.prepend(Module.new do
4
4
  # Installs the gems into the omnibus gemset.
5
5
  def install
6
6
  return super unless $CHEFSPEC_MODE
7
+
7
8
  cookbook_gems = Hash.new { |h, k| h[k] = [] }
8
9
 
9
10
  cookbook_collection.each do |cookbook_name, cookbook_version|
@@ -20,10 +21,10 @@ Chef::Cookbook::GemInstaller.prepend(Module.new do
20
21
  private
21
22
 
22
23
  def locate_gem(gem_name, gem_requirements)
23
- ::Gem::Specification::find_by_name(gem_name, gem_requirements)
24
+ ::Gem::Specification.find_by_name(gem_name, gem_requirements)
24
25
  rescue ::Gem::MissingSpecError
25
- gem_cmd = "gem install #{gem_name} --version '#{gem_requirements.join(', ')}'"
26
- gemfile_line = "gem '#{[gem_name, *gem_requirements].join('\', \'')}'"
26
+ gem_cmd = "gem install #{gem_name} --version '#{gem_requirements.join(", ")}'"
27
+ gemfile_line = "gem '#{[gem_name, *gem_requirements].join("', '")}'"
27
28
  warn "No matching version found for '#{gem_name}' in your gem environment.\n" \
28
29
  " - if you are using Chef Workstation, run the following command: \"chef #{gem_cmd}\"\n" \
29
30
  " - if you are using bundler, append \"#{gemfile_line}\" to your Gemfile and run \"bundle install\"\n" \
@@ -3,6 +3,7 @@ require "chef/cookbook_loader"
3
3
  Chef::CookbookLoader.prepend(Module.new do
4
4
  def all_directories_in_repo_paths
5
5
  return super unless $CHEFSPEC_MODE
6
+
6
7
  if Chef::Config[:chefspec_cookbook_root]
7
8
  # Hax.
8
9
  [Chef::Config[:chefspec_cookbook_root]]
@@ -1,4 +1,4 @@
1
- require 'chef/cookbook_uploader'
1
+ require "chef/cookbook_uploader"
2
2
 
3
3
  Chef::CookbookUploader.prepend(Module.new do |variable|
4
4
  #
@@ -1,4 +1,4 @@
1
- require 'chef/dsl/data_query'
1
+ require "chef/dsl/data_query"
2
2
 
3
3
  Chef::DSL::DataQuery.prepend(Module.new do
4
4
  # @see Chef::DSL::DataQuery#search
@@ -6,7 +6,7 @@ Chef::DSL::DataQuery.prepend(Module.new do
6
6
  return super unless Chef::Config[:solo] && $CHEFSPEC_MODE
7
7
 
8
8
  type = args[0]
9
- query = args[1] || '*:*'
9
+ query = args[1] || "*:*"
10
10
  stub = ChefSpec::Stubs::SearchRegistry.stub_for(type, query)
11
11
 
12
12
  if stub.nil?
@@ -14,7 +14,7 @@ Chef::DSL::DataQuery.prepend(Module.new do
14
14
  end
15
15
 
16
16
  if block
17
- Array(stub.result).each {|r| block.call(r) }
17
+ Array(stub.result).each { |r| block.call(r) }
18
18
  true
19
19
  else
20
20
  stub.result
@@ -22,6 +22,7 @@ else # >= 13.0
22
22
  Chef::Provider.prepend(Module.new do
23
23
  def compile_and_converge_action(&block)
24
24
  return super unless $CHEFSPEC_MODE
25
+
25
26
  instance_eval(&block)
26
27
  end
27
28
  end)
@@ -1,5 +1,5 @@
1
- require 'chef/provider'
2
- require_relative '../../api'
1
+ require "chef/provider"
2
+ require_relative "../../api"
3
3
 
4
4
  Chef::Provider.prepend(Module.new do
5
5
  def self.name
@@ -20,17 +20,20 @@ Chef::Provider.prepend(Module.new do
20
20
  if ChefSpec::API::StubsFor::HAS_SHELLOUT_COMPACTED.satisfied_by?(Gem::Version.create(Chef::VERSION))
21
21
  def shell_out_compacted(*args)
22
22
  return super unless $CHEFSPEC_MODE
23
- raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: 'provider', resource: new_resource)
23
+
24
+ raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "provider", resource: new_resource)
24
25
  end
25
26
 
26
27
  def shell_out_compacted!(*args)
27
28
  return super unless $CHEFSPEC_MODE
28
- shell_out_compacted(*args).tap {|c| c.error! }
29
+
30
+ shell_out_compacted(*args).tap(&:error!)
29
31
  end
30
32
  else
31
33
  def shell_out(*args)
32
34
  return super unless $CHEFSPEC_MODE
33
- raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: 'provider', resource: new_resource)
35
+
36
+ raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "provider", resource: new_resource)
34
37
  end
35
38
  end
36
39
  end)
@@ -1,4 +1,4 @@
1
- require 'chef/resource/freebsd_package'
1
+ require "chef/resource/freebsd_package"
2
2
 
3
3
  Chef::Resource::FreebsdPackage.prepend(Module.new do
4
4
  #
@@ -11,6 +11,7 @@ Chef::Resource::FreebsdPackage.prepend(Module.new do
11
11
  #
12
12
  def supports_pkgng?
13
13
  return super unless $CHEFSPEC_MODE
14
+
14
15
  true
15
16
  end
16
17
  end)
@@ -1,6 +1,6 @@
1
- require 'chef/resource'
2
- require 'chef/version'
3
- require_relative '../../api'
1
+ require "chef/resource"
2
+ require "chef/version"
3
+ require_relative "../../api"
4
4
 
5
5
  #
6
6
  # Three concerns:
@@ -29,8 +29,8 @@ module ChefSpec::Extensions::Chef::Resource
29
29
 
30
30
  def dup
31
31
  return super unless $CHEFSPEC_MODE
32
+
32
33
  # Also here be dragons.
33
- stack = caller
34
34
  super.tap do |dup_resource|
35
35
  # We're directly inside a load_current_resource, which is probably via
36
36
  # the load_current_value DSL system, so call this a current resource.
@@ -41,6 +41,7 @@ module ChefSpec::Extensions::Chef::Resource
41
41
  # mix of no-op and tracking concerns
42
42
  def run_action(action, notification_type = nil, notifying_resource = nil)
43
43
  return super unless $CHEFSPEC_MODE
44
+
44
45
  resolve_notification_references
45
46
  validate_action(action)
46
47
 
@@ -68,17 +69,20 @@ module ChefSpec::Extensions::Chef::Resource
68
69
  if ChefSpec::API::StubsFor::HAS_SHELLOUT_COMPACTED.satisfied_by?(Gem::Version.create(Chef::VERSION))
69
70
  def shell_out_compacted(*args)
70
71
  return super unless $CHEFSPEC_MODE
71
- raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: 'resource', resource: self)
72
+
73
+ raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "resource", resource: self)
72
74
  end
73
75
 
74
76
  def shell_out_compacted!(*args)
75
77
  return super unless $CHEFSPEC_MODE
76
- shell_out_compacted(*args).tap {|c| c.error! }
78
+
79
+ shell_out_compacted(*args).tap(&:error!)
77
80
  end
78
81
  else
79
82
  def shell_out(*args)
80
83
  return super unless $CHEFSPEC_MODE
81
- raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: 'resource', resource: self)
84
+
85
+ raise ChefSpec::Error::ShellOutNotStubbed.new(args: args, type: "resource", resource: self)
82
86
  end
83
87
  end
84
88
 
@@ -140,9 +144,9 @@ module ChefSpec::Extensions::Chef::Resource
140
144
  super
141
145
  end
142
146
 
143
- def action(sym, &block)
147
+ def action(sym, description: nil, &block)
144
148
  inject_actions(sym)
145
- super
149
+ super(sym, &block)
146
150
  end
147
151
 
148
152
  def allowed_actions(*actions)
@@ -168,6 +172,7 @@ module ChefSpec::Extensions::Chef::Resource
168
172
  def inject_actions(*actions)
169
173
  provides_names.each do |resource_name|
170
174
  next unless resource_name
175
+
171
176
  ChefSpec.define_matcher(resource_name)
172
177
  actions.each do |action|
173
178
  inject_method(:"#{action}_#{resource_name}", resource_name, action)
@@ -1,4 +1,4 @@
1
- require 'chef/run_context/cookbook_compiler'
1
+ require "chef/run_context/cookbook_compiler"
2
2
 
3
3
  Chef::RunContext::CookbookCompiler.prepend(Module.new do
4
4
  # List of compile phases as of Chef 14:
@@ -15,36 +15,44 @@ Chef::RunContext::CookbookCompiler.prepend(Module.new do
15
15
 
16
16
  def load_libraries_from_cookbook(cookbook)
17
17
  return super unless $CHEFSPEC_MODE
18
+
18
19
  $CHEFSPEC_LIBRARY_PRELOAD ||= {}
19
20
  # Already loaded this once.
20
21
  return if $CHEFSPEC_LIBRARY_PRELOAD[cookbook]
22
+
21
23
  $CHEFSPEC_LIBRARY_PRELOAD[cookbook] = true
22
24
  super
23
25
  end
24
26
 
25
27
  def load_ohai_plugins_from_cookbook(cookbook)
26
28
  return super unless $CHEFSPEC_MODE
29
+
27
30
  $CHEFSPEC_OHAI_PRELOAD ||= {}
28
31
  # Already loaded this once.
29
32
  return if $CHEFSPEC_OHAI_PRELOAD[cookbook]
33
+
30
34
  $CHEFSPEC_OHAI_PRELOAD[cookbook] = true
31
35
  super
32
36
  end
33
37
 
34
38
  def load_lwrps_from_cookbook(cookbook)
35
39
  return super unless $CHEFSPEC_MODE
40
+
36
41
  $CHEFSPEC_LWRP_PRELOAD ||= {}
37
42
  # Already loaded this once.
38
43
  return if $CHEFSPEC_LWRP_PRELOAD[cookbook]
44
+
39
45
  $CHEFSPEC_LWRP_PRELOAD[cookbook] = true
40
46
  super
41
47
  end
42
48
 
43
49
  def load_resource_definitions_from_cookbook(cookbook)
44
50
  return super unless $CHEFSPEC_MODE
51
+
45
52
  $CHEFSPEC_DEFINITION_PRELOAD ||= {}
46
53
  # Already loaded this once.
47
54
  return if $CHEFSPEC_DEFINITION_PRELOAD[cookbook]
55
+
48
56
  $CHEFSPEC_DEFINITION_PRELOAD[cookbook] = true
49
57
  super
50
58
  end
@@ -56,18 +64,21 @@ Chef::RunContext::CookbookCompiler.prepend(Module.new do
56
64
  def compile_ohai_plugins
57
65
  return super unless $CHEFSPEC_MODE
58
66
  return if $CHEFSPEC_PRELOAD
67
+
59
68
  super
60
69
  end
61
70
 
62
71
  def compile_attributes
63
72
  return super unless $CHEFSPEC_MODE
64
73
  return if $CHEFSPEC_PRELOAD
74
+
65
75
  super
66
76
  end
67
77
 
68
78
  def compile_recipes
69
79
  return super unless $CHEFSPEC_MODE
70
80
  return if $CHEFSPEC_PRELOAD
81
+
71
82
  super
72
83
  end
73
84
  end)
@@ -1,4 +1,4 @@
1
- require 'chef/mixin/securable'
1
+ require "chef/mixin/securable"
2
2
 
3
3
  class Chef
4
4
  module Mixin
@@ -1,4 +1,4 @@
1
- require 'ohai/system'
1
+ require "ohai/system"
2
2
 
3
3
  Ohai::System.prepend(Module.new do
4
4
  # If an Ohai segment exists, don't actually pull data in for ohai.
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require "rspec"
2
2
 
3
3
  module ChefSpec::Extensions
4
4
  module Chef
@@ -6,16 +6,16 @@ module ChefSpec::Extensions
6
6
  end
7
7
 
8
8
  # STOP! DO NOT ALPHABETIZE!
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'
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"
@@ -1,5 +1,5 @@
1
- require 'fileutils'
2
- require 'singleton'
1
+ require "fileutils" unless defined?(FileUtils)
2
+ require "singleton" unless defined?(Singleton)
3
3
 
4
4
  module ChefSpec
5
5
  class FileCachePathProxy
@@ -8,7 +8,7 @@ module ChefSpec
8
8
  attr_reader :file_cache_path
9
9
 
10
10
  def initialize
11
- @file_cache_path = Dir.mktmpdir(["chefspec", "file_cache_path"])
11
+ @file_cache_path = Dir.mktmpdir(%w{chefspec file_cache_path})
12
12
  at_exit { FileUtils.rm_rf(@file_cache_path) }
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
- require 'chef/formatters/base'
2
- require 'chef/formatters/error_mapper'
1
+ require "chef/formatters/base"
2
+ require "chef/formatters/error_mapper"
3
3
 
4
4
  module ChefSpec
5
5
  class ChefFormatter < Chef::Formatters::Base
@@ -202,7 +202,7 @@ module ChefSpec
202
202
  def converge_complete; end
203
203
 
204
204
  # Called before action is executed on a resource.
205
- def resource_action_start(resource, action, notification_type=nil, notifier=nil); end
205
+ def resource_action_start(resource, action, notification_type = nil, notifier = nil); end
206
206
 
207
207
  # Called when a resource fails, but will retry.
208
208
  def resource_failed_retriable(resource, action, retry_count, exception); end
@@ -1,10 +1,11 @@
1
1
  begin
2
- require 'librarian/chef/environment'
3
- require 'librarian/action/resolve'
4
- require 'librarian/action/install'
2
+ require "librarian/chef/environment"
3
+ require "librarian/action/resolve"
4
+ require "librarian/action/install"
5
5
  rescue LoadError
6
6
  raise ChefSpec::Error::GemLoadError.new(
7
- gem: 'librarian-chef', name: 'Librarian')
7
+ gem: "librarian-chef", name: "Librarian"
8
+ )
8
9
  end
9
10
 
10
11
  module ChefSpec
@@ -25,7 +26,7 @@ module ChefSpec
25
26
  #
26
27
  def setup!
27
28
  env = ::Librarian::Chef::Environment.new(project_path: Dir.pwd)
28
- @originalpath, env.config_db.local['path'] = env.config_db.local['path'], @tmpdir
29
+ @originalpath, env.config_db.local["path"] = env.config_db.local["path"], @tmpdir
29
30
  ::Librarian::Action::Resolve.new(env).run
30
31
  ::Librarian::Action::Install.new(env).run
31
32
 
@@ -37,7 +38,7 @@ module ChefSpec
37
38
  #
38
39
  def teardown!
39
40
  env = ::Librarian::Chef::Environment.new(project_path: Dir.pwd)
40
- env.config_db.local['path'] = @originalpath
41
+ env.config_db.local["path"] = @originalpath
41
42
 
42
43
  FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir)
43
44
  end