chefspec 8.0.1 → 9.3.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.
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.rb +29 -29
  6. data/lib/chefspec/api.rb +15 -13
  7. data/lib/chefspec/api/core.rb +3 -3
  8. data/lib/chefspec/api/described.rb +3 -5
  9. data/lib/chefspec/api/include_any_recipe.rb +24 -0
  10. data/lib/chefspec/api/stubs.rb +2 -2
  11. data/lib/chefspec/api/stubs_for.rb +23 -20
  12. data/lib/chefspec/berkshelf.rb +4 -4
  13. data/lib/chefspec/cacher.rb +2 -2
  14. data/lib/chefspec/coverage.rb +35 -40
  15. data/lib/chefspec/coverage/filters.rb +18 -15
  16. data/lib/chefspec/deprecations.rb +3 -3
  17. data/lib/chefspec/errors.rb +7 -7
  18. data/lib/chefspec/expect_exception.rb +2 -1
  19. data/lib/chefspec/extensions.rb +14 -13
  20. data/lib/chefspec/extensions/chef/client.rb +3 -3
  21. data/lib/chefspec/extensions/chef/conditional.rb +2 -1
  22. data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +5 -4
  23. data/lib/chefspec/extensions/chef/cookbook_loader.rb +1 -0
  24. data/lib/chefspec/extensions/chef/cookbook_uploader.rb +1 -1
  25. data/lib/chefspec/extensions/chef/data_query.rb +3 -3
  26. data/lib/chefspec/extensions/chef/lwrp_base.rb +1 -0
  27. data/lib/chefspec/extensions/chef/provider.rb +8 -5
  28. data/lib/chefspec/extensions/chef/resource.rb +18 -12
  29. data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
  30. data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +21 -1
  31. data/lib/chefspec/extensions/chef/securable.rb +1 -1
  32. data/lib/chefspec/extensions/ohai/system.rb +11 -0
  33. data/lib/chefspec/file_cache_path_proxy.rb +3 -3
  34. data/lib/chefspec/formatter.rb +15 -3
  35. data/lib/chefspec/librarian.rb +7 -6
  36. data/lib/chefspec/matchers.rb +9 -8
  37. data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
  38. data/lib/chefspec/matchers/include_any_recipe_matcher.rb +51 -0
  39. data/lib/chefspec/matchers/include_recipe_matcher.rb +1 -1
  40. data/lib/chefspec/matchers/link_to_matcher.rb +2 -2
  41. data/lib/chefspec/matchers/notifications_matcher.rb +5 -4
  42. data/lib/chefspec/matchers/render_file_matcher.rb +3 -3
  43. data/lib/chefspec/matchers/resource_matcher.rb +18 -16
  44. data/lib/chefspec/mixins/normalize.rb +1 -1
  45. data/lib/chefspec/policyfile.rb +6 -6
  46. data/lib/chefspec/renderer.rb +4 -4
  47. data/lib/chefspec/rspec.rb +1 -1
  48. data/lib/chefspec/runner.rb +1 -1
  49. data/lib/chefspec/server.rb +1 -1
  50. data/lib/chefspec/server_methods.rb +8 -8
  51. data/lib/chefspec/server_runner.rb +10 -10
  52. data/lib/chefspec/solo_runner.rb +26 -24
  53. data/lib/chefspec/stubs/command_registry.rb +1 -1
  54. data/lib/chefspec/stubs/command_stub.rb +1 -1
  55. data/lib/chefspec/stubs/data_bag_item_registry.rb +1 -1
  56. data/lib/chefspec/stubs/data_bag_item_stub.rb +1 -1
  57. data/lib/chefspec/stubs/data_bag_registry.rb +1 -1
  58. data/lib/chefspec/stubs/data_bag_stub.rb +1 -1
  59. data/lib/chefspec/stubs/registry.rb +1 -1
  60. data/lib/chefspec/stubs/search_registry.rb +2 -2
  61. data/lib/chefspec/stubs/search_stub.rb +2 -2
  62. data/lib/chefspec/util.rb +7 -7
  63. data/lib/chefspec/version.rb +1 -1
  64. data/lib/chefspec/zero_server.rb +4 -4
  65. data/spec/spec_helper.rb +3 -4
  66. data/spec/support/hash.rb +3 -3
  67. data/spec/unit/cacher_spec.rb +17 -17
  68. data/spec/unit/coverage/filters_spec.rb +16 -16
  69. data/spec/unit/deprecations_spec.rb +8 -9
  70. data/spec/unit/errors_spec.rb +15 -15
  71. data/spec/unit/expect_exception_spec.rb +9 -9
  72. data/spec/unit/macros_spec.rb +50 -50
  73. data/spec/unit/matchers/do_nothing_matcher.rb +1 -1
  74. data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +52 -0
  75. data/spec/unit/matchers/include_recipe_matcher_spec.rb +15 -15
  76. data/spec/unit/matchers/link_to_matcher_spec.rb +18 -18
  77. data/spec/unit/matchers/notifications_matcher_spec.rb +15 -16
  78. data/spec/unit/matchers/render_file_matcher_spec.rb +26 -26
  79. data/spec/unit/matchers/resource_matcher_spec.rb +1 -1
  80. data/spec/unit/matchers/state_attrs_matcher_spec.rb +24 -24
  81. data/spec/unit/matchers/subscribes_matcher_spec.rb +27 -29
  82. data/spec/unit/renderer_spec.rb +36 -36
  83. data/spec/unit/server_runner_spec.rb +6 -6
  84. data/spec/unit/solo_runner_spec.rb +69 -69
  85. data/spec/unit/stubs/command_registry_spec.rb +11 -11
  86. data/spec/unit/stubs/command_stub_spec.rb +26 -26
  87. data/spec/unit/stubs/data_bag_item_registry_spec.rb +17 -17
  88. data/spec/unit/stubs/data_bag_item_stub_spec.rb +14 -14
  89. data/spec/unit/stubs/data_bag_registry_spec.rb +16 -16
  90. data/spec/unit/stubs/data_bag_stub_spec.rb +13 -13
  91. data/spec/unit/stubs/registry_spec.rb +9 -9
  92. data/spec/unit/stubs/search_registry_spec.rb +17 -17
  93. data/spec/unit/stubs/search_stub_spec.rb +14 -14
  94. data/spec/unit/stubs/stub_spec.rb +22 -22
  95. metadata +16 -12
@@ -0,0 +1,51 @@
1
+ module ChefSpec::Matchers
2
+ class IncludeAnyRecipeMatcher
3
+ def matches?(runner)
4
+ @runner = runner
5
+ !(loaded_recipes - run_list_recipes).empty?
6
+ end
7
+
8
+ def description
9
+ "include any recipe"
10
+ end
11
+
12
+ def failure_message
13
+ "expected to include any recipe"
14
+ end
15
+
16
+ def failure_message_when_negated
17
+ "expected not to include any recipes"
18
+ end
19
+
20
+ private
21
+
22
+ #
23
+ # The list of run_list recipes on the Chef run (normalized)
24
+ #
25
+ # @return [Array<String>]
26
+ #
27
+ def run_list_recipes
28
+ @runner.run_context.node.run_list.run_list_items.map { |x| with_default(x.name) }
29
+ end
30
+
31
+ #
32
+ # Automatically appends "+::default+" to recipes that need them.
33
+ #
34
+ # @param [String] name
35
+ #
36
+ # @return [String]
37
+ #
38
+ def with_default(name)
39
+ name.include?("::") ? name : "#{name}::default"
40
+ end
41
+
42
+ #
43
+ # The list of loaded recipes on the Chef run (normalized)
44
+ #
45
+ # @return [Array<String>]
46
+ #
47
+ def loaded_recipes
48
+ @runner.run_context.loaded_recipes.map { |name| with_default(name) }
49
+ end
50
+ end
51
+ end
@@ -31,7 +31,7 @@ module ChefSpec::Matchers
31
31
  # @return [String]
32
32
  #
33
33
  def with_default(name)
34
- name.include?('::') ? name : "#{name}::default"
34
+ name.include?("::") ? name : "#{name}::default"
35
35
  end
36
36
 
37
37
  #
@@ -11,8 +11,8 @@ module ChefSpec::Matchers
11
11
  ChefSpec::Coverage.cover!(@link)
12
12
 
13
13
  @link.is_a?(Chef::Resource::Link) &&
14
- @link.performed_action?(:create) &&
15
- @path === @link.to
14
+ @link.performed_action?(:create) &&
15
+ @path === @link.to
16
16
  else
17
17
  false
18
18
  end
@@ -14,8 +14,8 @@ module ChefSpec::Matchers
14
14
  if @resource
15
15
  block = Proc.new do |notified|
16
16
  resource_name(notified.resource).to_s == @expected_resource_type &&
17
- (@expected_resource_name === notified.resource.identity.to_s || @expected_resource_name === notified.resource.name.to_s) &&
18
- matches_action?(notified)
17
+ (@expected_resource_name === notified.resource.identity.to_s || @expected_resource_name === notified.resource.name.to_s) &&
18
+ matches_action?(notified)
19
19
  end
20
20
 
21
21
  if @immediately
@@ -115,6 +115,7 @@ module ChefSpec::Matchers
115
115
 
116
116
  def matches_action?(notification)
117
117
  return true if @action.nil?
118
+
118
119
  @action == notification.action.to_sym
119
120
  end
120
121
 
@@ -130,12 +131,12 @@ module ChefSpec::Matchers
130
131
  type = :delayed
131
132
  end
132
133
 
133
- %Q{ "#{notifying_resource.to_s}" notifies "#{resource_name(resource)}[#{resource.name}]" to :#{notification.action}, :#{type}}
134
+ %Q{ "#{notifying_resource}" notifies "#{resource_name(resource)}[#{resource.name}]" to :#{notification.action}, :#{type}}
134
135
  end
135
136
 
136
137
  def format_notifications
137
138
  all_notifications.map do |notification|
138
- ' ' + format_notification(notification)
139
+ " " + format_notification(notification)
139
140
  end.join("\n")
140
141
  end
141
142
  end
@@ -87,8 +87,8 @@ module ChefSpec::Matchers
87
87
 
88
88
  def resource
89
89
  @resource ||= @runner.find_resource(:cookbook_file, @path) ||
90
- @runner.find_resource(:file, @path) ||
91
- @runner.find_resource(:template, @path)
90
+ @runner.find_resource(:file, @path) ||
91
+ @runner.find_resource(:template, @path)
92
92
  end
93
93
 
94
94
  #
@@ -99,7 +99,7 @@ module ChefSpec::Matchers
99
99
  # @return [true, false]
100
100
  #
101
101
  def has_create_action?
102
- [:create, :create_if_missing].any? { |action| resource.performed_action?(action) }
102
+ %i{create create_if_missing}.any? { |action| resource.performed_action?(action) }
103
103
  end
104
104
 
105
105
  #
@@ -1,5 +1,5 @@
1
- require 'rspec/matchers/expecteds_for_multiple_diffs'
2
- require 'rspec/expectations/fail_with'
1
+ require "rspec/matchers/expecteds_for_multiple_diffs"
2
+ require "rspec/expectations/fail_with"
3
3
 
4
4
  module ChefSpec::Matchers
5
5
  class ResourceMatcher
@@ -15,13 +15,15 @@ module ChefSpec::Matchers
15
15
  end
16
16
 
17
17
  def at_compile_time
18
- raise ArgumentError, 'Cannot specify both .at_converge_time and .at_compile_time!' if @converge_time
18
+ raise ArgumentError, "Cannot specify both .at_converge_time and .at_compile_time!" if @converge_time
19
+
19
20
  @compile_time = true
20
21
  self
21
22
  end
22
23
 
23
24
  def at_converge_time
24
- raise ArgumentError, 'Cannot specify both .at_compile_time and .at_converge_time!' if @compile_time
25
+ raise ArgumentError, "Cannot specify both .at_compile_time and .at_converge_time!" if @compile_time
26
+
25
27
  @converge_time = true
26
28
  self
27
29
  end
@@ -55,20 +57,20 @@ module ChefSpec::Matchers
55
57
  if resource
56
58
  if unmatched_parameters.empty?
57
59
  if @compile_time
58
- %Q{expected "#{resource.to_s}" to be run at compile time}
60
+ %Q{expected "#{resource}" to be run at compile time}
59
61
  else
60
- %Q{expected "#{resource.to_s}" to be run at converge time}
62
+ %Q{expected "#{resource}" to be run at converge time}
61
63
  end
62
64
  else
63
- message = %Q{expected "#{resource.to_s}" to have parameters:} \
65
+ message = %Q{expected "#{resource}" to have parameters:} \
64
66
  "\n\n" \
65
67
  " " + unmatched_parameters.collect { |parameter, h|
66
- msg = "#{parameter} #{h[:expected].inspect}, was #{h[:actual].inspect}"
67
- diff = ::RSpec::Matchers::ExpectedsForMultipleDiffs.from(h[:expected]) \
68
- .message_with_diff(message, ::RSpec::Expectations::differ, h[:actual])
69
- msg += diff if diff
70
- msg
71
- }.join("\n ")
68
+ msg = "#{parameter} #{h[:expected].inspect}, was #{h[:actual].inspect}"
69
+ diff = ::RSpec::Matchers::ExpectedsForMultipleDiffs.from(h[:expected]) \
70
+ .message_with_diff(message, ::RSpec::Expectations.differ, h[:actual])
71
+ msg += diff if diff
72
+ msg
73
+ }.join("\n ")
72
74
  end
73
75
  else
74
76
  %Q{expected "#{@resource_name}[#{@expected_identity}]"} \
@@ -81,9 +83,9 @@ module ChefSpec::Matchers
81
83
 
82
84
  def failure_message_when_negated
83
85
  if resource
84
- message = %Q{expected "#{resource.to_s}" actions #{resource.performed_actions.inspect} to not exist}
86
+ message = %Q{expected "#{resource}" actions #{resource.performed_actions.inspect} to not exist}
85
87
  else
86
- message = %Q{expected "#{resource.to_s}" to not exist}
88
+ message = %Q{expected "#{resource}" to not exist}
87
89
  end
88
90
 
89
91
  message << " at compile time" if @compile_time
@@ -115,7 +117,7 @@ module ChefSpec::Matchers
115
117
  if parameter == :source
116
118
  # Chef 11+ stores the source parameter internally as an Array
117
119
  Array(expected) == Array(value)
118
- elsif expected.kind_of?(Class)
120
+ elsif expected.is_a?(Class)
119
121
  # Ruby can't compare classes with ===
120
122
  expected == value
121
123
  else
@@ -16,7 +16,7 @@ module ChefSpec
16
16
  else
17
17
  name = thing
18
18
  end
19
- name.to_s.gsub('-', '_').to_sym
19
+ name.to_s.gsub("-", "_").to_sym
20
20
  end
21
21
  end
22
22
  end
@@ -1,8 +1,8 @@
1
1
  begin
2
- require 'chef-cli/policyfile_services/export_repo'
3
- require 'chef-cli/policyfile_services/install'
2
+ require "chef-cli/policyfile_services/export_repo"
3
+ require "chef-cli/policyfile_services/install"
4
4
  rescue LoadError
5
- raise ChefSpec::Error::GemLoadError.new(gem: 'chef-cli', name: 'ChefCLI')
5
+ raise ChefSpec::Error::GemLoadError.new(gem: "chef-cli", name: "ChefCLI")
6
6
  end
7
7
 
8
8
  module ChefSpec
@@ -24,7 +24,7 @@ module ChefSpec
24
24
  def setup!
25
25
  policyfile_path = RSpec.configuration.policyfile_path
26
26
  if policyfile_path.nil?
27
- policyfile_path = File.join(Dir.pwd, 'Policyfile.rb')
27
+ policyfile_path = File.join(Dir.pwd, "Policyfile.rb")
28
28
  end
29
29
 
30
30
  installer = ChefCLI::PolicyfileServices::Install.new(
@@ -44,8 +44,8 @@ module ChefSpec
44
44
 
45
45
  ::RSpec.configure do |config|
46
46
  config.cookbook_path = [
47
- File.join(@tmpdir, 'cookbooks'),
48
- File.join(@tmpdir, 'cookbook_artifacts')
47
+ File.join(@tmpdir, "cookbooks"),
48
+ File.join(@tmpdir, "cookbook_artifacts"),
49
49
  ]
50
50
  end
51
51
  end
@@ -1,6 +1,6 @@
1
1
  begin
2
- require 'chef/mixin/template'
3
- require 'chef/provider/template_finder'
2
+ require "chef/mixin/template"
3
+ require "chef/provider/template_finder"
4
4
  rescue LoadError
5
5
  end
6
6
 
@@ -67,8 +67,8 @@ module ChefSpec
67
67
  if Chef::Mixin::Template.const_defined?(:TemplateContext) # Chef 11+
68
68
  template_context = Chef::Mixin::Template::TemplateContext.new([])
69
69
  template_context.update({
70
- :node => chef_run.node,
71
- :template_finder => template_finder(chef_run, cookbook_name),
70
+ node: chef_run.node,
71
+ template_finder: template_finder(chef_run, cookbook_name),
72
72
  }.merge(template.variables))
73
73
  if template.respond_to?(:helper_modules) # Chef 11.4+
74
74
  template_context._extend_modules(template.helper_modules)
@@ -1,5 +1,5 @@
1
1
  RSpec.configure do |config|
2
- unless ENV['CHEFSPEC_NO_INCLUDE']
2
+ unless ENV["CHEFSPEC_NO_INCLUDE"]
3
3
  config.include(ChefSpec::API)
4
4
  end
5
5
 
@@ -1,4 +1,4 @@
1
- require "chefspec/solo_runner"
1
+ require_relative "solo_runner"
2
2
 
3
3
  module ChefSpec
4
4
  # As we start to migrate back to only SoloRunner, include this alias for now.
@@ -1,4 +1,4 @@
1
1
  # @todo Remove in v5.0.0
2
- require_relative 'deprecations'
2
+ require_relative "deprecations"
3
3
  deprecated "require 'chefspec/server' is no longer required and " \
4
4
  "will be removed in the next major release."
@@ -88,11 +88,11 @@ module ChefSpec
88
88
  EOH
89
89
  end
90
90
 
91
- entity :client, Chef::Client, 'clients'
92
- entity :data_bag, Chef::DataBag, 'data'
93
- entity :environment, Chef::Environment, 'environments'
94
- entity :node, Chef::Node, 'nodes'
95
- entity :role, Chef::Role, 'roles'
91
+ entity :client, Chef::Client, "clients"
92
+ entity :data_bag, Chef::DataBag, "data"
93
+ entity :environment, Chef::Environment, "environments"
94
+ entity :node, Chef::Node, "nodes"
95
+ entity :role, Chef::Role, "roles"
96
96
 
97
97
  #
98
98
  # Create a new data_bag on the Chef Server. This overrides the method
@@ -104,7 +104,7 @@ module ChefSpec
104
104
  # the data to load into the data bag
105
105
  #
106
106
  def create_data_bag(name, data = {})
107
- load_data(name, 'data', data)
107
+ load_data(name, "data", data)
108
108
  end
109
109
 
110
110
  #
@@ -138,7 +138,7 @@ module ChefSpec
138
138
  data = JSON.fast_generate(data)
139
139
  end
140
140
 
141
- load_data(name, 'nodes', data)
141
+ load_data(name, "nodes", data)
142
142
  end
143
143
  alias_method :update_node, :create_node
144
144
 
@@ -161,7 +161,7 @@ module ChefSpec
161
161
  # Get the path to an item in the data store.
162
162
  #
163
163
  def get(*args)
164
- args.unshift('organizations', 'chef')
164
+ args.unshift("organizations", "chef")
165
165
 
166
166
  if args.size == 3
167
167
  server.data_store.list(args)
@@ -1,10 +1,10 @@
1
- require 'chef/cookbook_loader'
2
- require 'chef/cookbook_uploader'
1
+ require "chef/cookbook_loader"
2
+ require "chef/cookbook_uploader"
3
3
 
4
- require_relative 'zero_server'
5
- require_relative 'file_cache_path_proxy'
6
- require_relative 'server_methods'
7
- require_relative 'solo_runner'
4
+ require_relative "zero_server"
5
+ require_relative "file_cache_path_proxy"
6
+ require_relative "server_methods"
7
+ require_relative "solo_runner"
8
8
 
9
9
  module ChefSpec
10
10
  class ServerRunner < SoloRunner
@@ -54,8 +54,8 @@ module ChefSpec
54
54
  #
55
55
  def client_key
56
56
  tmp = Dir.mktmpdir
57
- path = File.join(tmp, 'client.pem')
58
- File.open(path, 'wb') { |f| f.write(ChefZero::PRIVATE_KEY) }
57
+ path = File.join(tmp, "client.pem")
58
+ File.open(path, "wb") { |f| f.write(ChefZero::PRIVATE_KEY) }
59
59
  at_exit { FileUtils.rm_rf(tmp) }
60
60
  path
61
61
  end
@@ -64,8 +64,8 @@ module ChefSpec
64
64
  def apply_chef_config!
65
65
  super
66
66
  Chef::Config[:client_key] = client_key
67
- Chef::Config[:client_name] = 'chefspec'
68
- Chef::Config[:node_name] = 'chefspec'
67
+ Chef::Config[:client_name] = "chefspec"
68
+ Chef::Config[:node_name] = "chefspec"
69
69
  Chef::Config[:solo] = false
70
70
  Chef::Config[:solo_legacy_mode] = false
71
71
 
@@ -1,9 +1,9 @@
1
- require 'fauxhai'
2
- require 'chef/client'
3
- require 'chef/cookbook/metadata'
4
- require 'chef/mash'
5
- require 'chef/providers'
6
- require 'chef/resources'
1
+ require "fauxhai"
2
+ require "chef/client"
3
+ require "chef/cookbook/metadata"
4
+ require "chef/mash"
5
+ require "chef/providers"
6
+ require "chef/resources"
7
7
 
8
8
  module ChefSpec
9
9
  class SoloRunner
@@ -123,6 +123,7 @@ module ChefSpec
123
123
  if converge_val.is_a?(Exception)
124
124
  raise converge_val
125
125
  end
126
+
126
127
  self
127
128
  end
128
129
 
@@ -136,7 +137,7 @@ module ChefSpec
136
137
  #
137
138
  def converge_block(&block)
138
139
  converge do
139
- recipe = Chef::Recipe.new(cookbook_name, '_test', run_context)
140
+ recipe = Chef::Recipe.new(cookbook_name, "_test", run_context)
140
141
  recipe.instance_exec(&block)
141
142
  end
142
143
  end
@@ -149,7 +150,8 @@ module ChefSpec
149
150
  #
150
151
  def preload!
151
152
  # Flag to disable preloading for situations where it doesn't make sense.
152
- return if ENV['CHEFSPEC_NO_PRELOAD']
153
+ return if ENV["CHEFSPEC_NO_PRELOAD"]
154
+
153
155
  begin
154
156
  old_preload = $CHEFSPEC_PRELOAD
155
157
  $CHEFSPEC_PRELOAD = true
@@ -292,7 +294,8 @@ module ChefSpec
292
294
  # Respond to custom matchers defined by the user.
293
295
  #
294
296
  def method_missing(m, *args, &block)
295
- if block = ChefSpec.matchers[resource_name(m.to_sym)]
297
+ block = ChefSpec.matchers[resource_name(m.to_sym)]
298
+ if block
296
299
  instance_exec(args.first, &block)
297
300
  else
298
301
  super
@@ -358,11 +361,11 @@ module ChefSpec
358
361
  # @return [String]
359
362
  #
360
363
  def calling_cookbook_root(options, kaller)
361
- calling_spec = options[:spec_declaration_locations] || kaller.find { |line| line =~ /\/spec/ }
364
+ calling_spec = options[:spec_declaration_locations] || kaller.find { |line| line =~ %r{/spec} }
362
365
  raise Error::CookbookPathNotFound if calling_spec.nil?
363
366
 
364
367
  bits = calling_spec.split(/:[0-9]/, 2).first.split(File::SEPARATOR)
365
- spec_dir = bits.index('spec') || 0
368
+ spec_dir = bits.index("spec") || 0
366
369
 
367
370
  File.join(bits.slice(0, spec_dir))
368
371
  end
@@ -378,7 +381,7 @@ module ChefSpec
378
381
  # @return [String]
379
382
  #
380
383
  def calling_cookbook_path(options, kaller)
381
- File.expand_path(File.join(calling_cookbook_root(options, kaller), '..'))
384
+ File.expand_path(File.join(calling_cookbook_root(options, kaller), ".."))
382
385
  end
383
386
 
384
387
  #
@@ -388,7 +391,7 @@ module ChefSpec
388
391
  #
389
392
  def default_role_path
390
393
  Pathname.new(Dir.pwd).ascend do |path|
391
- possible = File.join(path, 'roles')
394
+ possible = File.join(path, "roles")
392
395
  return possible if File.exist?(possible)
393
396
  end
394
397
 
@@ -402,7 +405,7 @@ module ChefSpec
402
405
  #
403
406
  def default_environment_path
404
407
  Pathname.new(Dir.pwd).ascend do |path|
405
- possible = File.join(path, 'environments')
408
+ possible = File.join(path, "environments")
406
409
  return possible if File.exist?(possible)
407
410
  end
408
411
 
@@ -459,7 +462,7 @@ module ChefSpec
459
462
  # @return [Chef::Cookbook::Metadata]
460
463
  #
461
464
  def cookbook
462
- @cookbook ||= Chef::Cookbook::Metadata.new.tap {|m| m.from_file("#{options[:cookbook_root]}/metadata.rb") }
465
+ @cookbook ||= Chef::Cookbook::Metadata.new.tap { |m| m.from_file("#{options[:cookbook_root]}/metadata.rb") }
463
466
  end
464
467
 
465
468
  #
@@ -470,12 +473,11 @@ module ChefSpec
470
473
  def cookbook_name
471
474
  # Try to figure out the name of this cookbook, pretending this block
472
475
  # is in the name context as the cookbook under test.
473
- begin
474
- cookbook.name
475
- rescue IOError
476
- # Old cookbook, has no metadata, use the folder name I guess.
477
- File.basename(options[:cookbook_root])
478
- end
476
+
477
+ cookbook.name
478
+ rescue IOError
479
+ # Old cookbook, has no metadata, use the folder name I guess.
480
+ File.basename(options[:cookbook_root])
479
481
  end
480
482
 
481
483
  #
@@ -489,8 +491,8 @@ module ChefSpec
489
491
 
490
492
  Chef::Config.reset!
491
493
  Chef::Config.formatters.clear
492
- Chef::Config.add_formatter('chefspec')
493
- Chef::Config[:cache_type] = 'Memory'
494
+ Chef::Config.add_formatter("chefspec")
495
+ Chef::Config[:cache_type] = "Memory"
494
496
  Chef::Config[:client_key] = nil
495
497
  Chef::Config[:client_name] = nil
496
498
  Chef::Config[:node_name] = nil
@@ -506,7 +508,7 @@ module ChefSpec
506
508
  Chef::Config[:force_logger] = true
507
509
  Chef::Config[:solo] = true
508
510
  Chef::Config[:solo_legacy_mode] = true
509
- Chef::Config[:use_policyfile] = false
511
+ Chef::Config[:use_policyfile] = false
510
512
  Chef::Config[:environment_path] = @options[:environment_path]
511
513
  end
512
514