chefspec 7.4.0 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 811f21e393d16be39c8162bbe17c1157d214ce0eb378e8d19e686683fad4160b
4
- data.tar.gz: 764db71993cd015961d195d39dc1c99a74bda29311a3fc69210961e4482d6ba9
3
+ metadata.gz: c20bc92ebea039d7261547ec0e91686f1c4c83e57f7bd19e98f4a4e4fce13aa3
4
+ data.tar.gz: b6f4060d3844074dfffe298c3a5d0d75a766926abf41e80dbb7b95c2aa26500c
5
5
  SHA512:
6
- metadata.gz: b7b68c00204307439f31270eb1ae14360d1750aabc7e7f87c2128337331fb29b6041858132f218fee76fd65c8d2903739816c1be4a8f268646c66fd10449b5a9
7
- data.tar.gz: d25a404af72648245718dc0ee6519023754c0c6f111f87746edb611e6c17856571bc183e17fd1284b33709ddebd8a0ba36c91a0f4245403db49bbd0d7e2a09b3
6
+ metadata.gz: 8446ad09b864f601169c69f635ee93fd1089ca8c4031e43884d9c87495ce0a57c86d3620ad9de1c2ddb36ceb1d66074352eeacce862a11dd8e3c7303cc0c19f3
7
+ data.tar.gz: 8d4db22787020c88195ce7ea76bd517b94ab293463b2dddda47614dbd867d8d5490a6a8d77b794bdd273ceca2903d58f46151302482021767c5686f2c549a299
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.files = %w{LICENSE Rakefile Gemfile chefspec.gemspec} + Dir.glob("{lib,templates,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
22
22
  s.require_paths = ['lib']
23
23
 
24
- s.required_ruby_version = '>= 2.3'
24
+ s.required_ruby_version = '>= 2.4'
25
25
 
26
- s.add_dependency 'chef', '>= 13'
27
- s.add_dependency 'fauxhai', '>= 6.11'
26
+ s.add_dependency 'chef', '>= 14'
27
+ s.add_dependency 'chef-cli'
28
+ s.add_dependency 'fauxhai-ng', '>= 7.5'
28
29
  s.add_dependency 'rspec', '~> 3.0'
29
30
  end
@@ -3,6 +3,7 @@ module ChefSpec
3
3
  autoload :Core, 'chefspec/api/core'
4
4
  autoload :Described, 'chefspec/api/described'
5
5
  autoload :DoNothing, 'chefspec/api/do_nothing'
6
+ autoload :IncludeAnyRecipe, 'chefspec/api/include_any_recipe'
6
7
  autoload :IncludeRecipe, 'chefspec/api/include_recipe'
7
8
  autoload :Link, 'chefspec/api/link'
8
9
  autoload :Notifications, 'chefspec/api/notifications'
@@ -19,6 +20,7 @@ module ChefSpec
19
20
  klass.include(ChefSpec::API::Core)
20
21
  klass.include(ChefSpec::API::Described)
21
22
  klass.include(ChefSpec::API::DoNothing)
23
+ klass.include(ChefSpec::API::IncludeAnyRecipe)
22
24
  klass.include(ChefSpec::API::IncludeRecipe)
23
25
  klass.include(ChefSpec::API::DoNothing)
24
26
  klass.include(ChefSpec::API::RenderFile)
@@ -0,0 +1,24 @@
1
+ module ChefSpec
2
+ module API
3
+ module IncludeAnyRecipe
4
+ #
5
+ # Assert that a Chef run includes any recipe.
6
+ #
7
+ # include_recipe 'apache2::default'
8
+ #
9
+ # The Examples section demonstrates the different ways to test an
10
+ # +include_any_recipe+ directive with ChefSpec.
11
+ #
12
+ # @example Assert the Chef run did not include any recipes
13
+ # expect(chef_run).not_to include_any_recipe
14
+ #
15
+ #
16
+ # @return [ChefSpec::Matchers::IncludeAnyRecipeMatcher]
17
+ #
18
+ def include_any_recipe
19
+ ChefSpec::Matchers::IncludeAnyRecipeMatcher.new
20
+ end
21
+ alias_method :include_any_recipes, :include_any_recipe
22
+ end
23
+ end
24
+ end
@@ -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.is_a?(Chef::Provider) ? object.new_resource : 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 current_resource [Boolean] If true, also register stubs for current_resource objects on the same target.
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 if !current_resource
63
64
  _chefspec_stubs_for_registry[:resource][target] << block
64
- stubs_for_current_resource(target, &block) if current_resource
65
+ stubs_for_current_value(target, &block) if current_value
65
66
  end
66
67
 
67
- # Register stubs for current_resource objects.
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 stubs_for_current_resource(target=nil, &block)
74
- _chefspec_stubs_for_registry[:current_resource][target] << block
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
  #
@@ -111,10 +113,11 @@ module ChefSpec
111
113
  before { stubs_for_resource(*args, &block) }
112
114
  end
113
115
 
114
- # (see StubsFor#stubs_for_current_resource)
115
- def stubs_for_current_resource(*args, &block)
116
- before { stubs_for_current_resource(*args, &block) }
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)
@@ -18,3 +18,4 @@ require_relative 'extensions/chef/lwrp_base'
18
18
  require_relative 'extensions/chef/resource/freebsd_package'
19
19
  require_relative 'extensions/chef/run_context/cookbook_compiler'
20
20
  require_relative 'extensions/chef/cookbook_loader'
21
+ require_relative 'extensions/ohai/system'
@@ -25,7 +25,7 @@ Chef::Cookbook::GemInstaller.prepend(Module.new do
25
25
  gem_cmd = "gem install #{gem_name} --version '#{gem_requirements.join(', ')}'"
26
26
  gemfile_line = "gem '#{[gem_name, *gem_requirements].join('\', \'')}'"
27
27
  warn "No matching version found for '#{gem_name}' in your gem environment.\n" \
28
- " - if you are using ChefDK, run the following command: \"chef #{gem_cmd}\"\n" \
28
+ " - if you are using Chef Workstation, run the following command: \"chef #{gem_cmd}\"\n" \
29
29
  " - if you are using bundler, append \"#{gemfile_line}\" to your Gemfile and run \"bundle install\"\n" \
30
30
  " - otherwise run: \"#{gem_cmd}\""
31
31
  end
@@ -1,5 +1,5 @@
1
1
  require 'chef/provider'
2
- require 'chefspec/api'
2
+ require_relative '../../api'
3
3
 
4
4
  Chef::Provider.prepend(Module.new do
5
5
  def self.name
@@ -1,6 +1,6 @@
1
1
  require 'chef/resource'
2
2
  require 'chef/version'
3
- require 'chefspec/api'
3
+ require_relative '../../api'
4
4
 
5
5
  #
6
6
  # Three concerns:
@@ -21,7 +21,8 @@ module ChefSpec::Extensions::Chef::Resource
21
21
  # If we're directly inside a `load_current_resource`, this is probably
22
22
  # something like `new_resource.class.new` so we want to call this a current_resource,
23
23
  # Otherwise it's probably a normal resource instantiation.
24
- mode = caller[1].include?("`load_current_resource'") ? :current_resource : :resource
24
+ mode = :resource
25
+ mode = :current_value if caller.any? { |x| x.include?("`load_current_resource'") || x.include?("`load_after_resource'") }
25
26
  ChefSpec::API::StubsFor.setup_stubs_for(self, mode)
26
27
  end
27
28
  end
@@ -33,7 +34,7 @@ module ChefSpec::Extensions::Chef::Resource
33
34
  super.tap do |dup_resource|
34
35
  # We're directly inside a load_current_resource, which is probably via
35
36
  # the load_current_value DSL system, so call this a current resource.
36
- ChefSpec::API::StubsFor.setup_stubs_for(dup_resource, :current_resource) if stack.first.include?("`load_current_resource'")
37
+ ChefSpec::API::StubsFor.setup_stubs_for(dup_resource, :current_value) if caller.any? { |x| x.include?("`load_current_resource'") || x.include?("`load_after_resource'") }
37
38
  end
38
39
  end
39
40
 
@@ -133,7 +134,7 @@ module ChefSpec::Extensions::Chef::Resource
133
134
  super
134
135
  end
135
136
 
136
- def provides(name, *args, &block)
137
+ def provides(name, **options, &block)
137
138
  provides_names << name unless provides_names.include?(name)
138
139
  inject_actions(*allowed_actions)
139
140
  super
@@ -22,6 +22,15 @@ Chef::RunContext::CookbookCompiler.prepend(Module.new do
22
22
  super
23
23
  end
24
24
 
25
+ def load_ohai_plugins_from_cookbook(cookbook)
26
+ return super unless $CHEFSPEC_MODE
27
+ $CHEFSPEC_OHAI_PRELOAD ||= {}
28
+ # Already loaded this once.
29
+ return if $CHEFSPEC_OHAI_PRELOAD[cookbook]
30
+ $CHEFSPEC_OHAI_PRELOAD[cookbook] = true
31
+ super
32
+ end
33
+
25
34
  def load_lwrps_from_cookbook(cookbook)
26
35
  return super unless $CHEFSPEC_MODE
27
36
  $CHEFSPEC_LWRP_PRELOAD ||= {}
@@ -0,0 +1,11 @@
1
+ require 'ohai/system'
2
+
3
+ Ohai::System.prepend(Module.new do
4
+ # If an Ohai segment exists, don't actually pull data in for ohai.
5
+ # (we have fake data for that)
6
+ # @see Ohai::System#run_additional_plugins
7
+ def run_additional_plugins(plugin_path)
8
+ return super unless $CHEFSPEC_MODE
9
+ # noop
10
+ end
11
+ end)
@@ -133,6 +133,18 @@ module ChefSpec
133
133
  # Called when LWRPs are finished loading
134
134
  def lwrp_load_complete; end
135
135
 
136
+ # Called when an ohai plugin file loading starts
137
+ def ohai_plugin_load_start(file_count); end
138
+
139
+ # Called when an ohai plugin file has been loaded
140
+ def ohai_plugin_file_loaded(path); end
141
+
142
+ # Called when an ohai plugin file has an error on load.
143
+ def ohai_plugin_file_load_failed(path, exception); end
144
+
145
+ # Called when an ohai plugin file loading has finished
146
+ def ohai_plugin_load_complete; end
147
+
136
148
  # Called before attribute files are loaded
137
149
  def attribute_load_start(attribute_file_count); end
138
150
 
@@ -1,6 +1,7 @@
1
1
  module ChefSpec
2
2
  module Matchers
3
3
  require_relative 'matchers/do_nothing_matcher'
4
+ require_relative 'matchers/include_any_recipe_matcher'
4
5
  require_relative 'matchers/include_recipe_matcher'
5
6
  require_relative 'matchers/link_to_matcher'
6
7
  require_relative 'matchers/notifications_matcher'
@@ -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
@@ -1,8 +1,8 @@
1
1
  begin
2
- require 'chef-dk/policyfile_services/export_repo'
3
- require 'chef-dk/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-dk', name: 'ChefDK')
5
+ raise ChefSpec::Error::GemLoadError.new(gem: 'chef-cli', name: 'ChefCLI')
6
6
  end
7
7
 
8
8
  module ChefSpec
@@ -27,14 +27,14 @@ module ChefSpec
27
27
  policyfile_path = File.join(Dir.pwd, 'Policyfile.rb')
28
28
  end
29
29
 
30
- installer = ChefDK::PolicyfileServices::Install.new(
30
+ installer = ChefCLI::PolicyfileServices::Install.new(
31
31
  policyfile: policyfile_path,
32
- ui: ChefDK::UI.null
32
+ ui: ChefCLI::UI.null
33
33
  )
34
34
 
35
35
  installer.run
36
36
 
37
- exporter = ChefDK::PolicyfileServices::ExportRepo.new(
37
+ exporter = ChefCLI::PolicyfileServices::ExportRepo.new(
38
38
  policyfile: policyfile_path,
39
39
  export_dir: @tmpdir
40
40
  )
@@ -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,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '7.4.0'
2
+ VERSION = '9.2.0'
3
3
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChefSpec::Matchers::IncludeAnyRecipeMatcher do
4
+ let(:node) { double('Chef::Node', run_list: run_list) }
5
+ let(:run_list) { double('Chef::RunList', run_list_items: run_list_items) }
6
+ let(:run_list_items) { [run_list_item_one] }
7
+ let(:run_list_item_one) { double('Chef::RunList::RunListItem', name: 'one') }
8
+ let(:run_list_item_two) { double('Chef::RunList::RunListItem', name: 'two') }
9
+ let(:loaded_recipes) { %w(one) }
10
+ let(:chef_run) { double('chef run', run_context: { loaded_recipes: loaded_recipes, node: node }) }
11
+
12
+ subject { described_class.new }
13
+
14
+ describe '#failure_message' do
15
+ it 'has the right value' do
16
+ subject.matches?(chef_run)
17
+ expect(subject.failure_message).to eq('expected to include any recipe')
18
+ end
19
+ end
20
+
21
+ describe '#failure_message_when_negated' do
22
+ it 'has the right value' do
23
+ subject.matches?(chef_run)
24
+ expect(subject.failure_message_when_negated).to eq('expected not to include any recipes')
25
+ end
26
+ end
27
+
28
+ describe '#description' do
29
+ it 'has the right value' do
30
+ subject.matches?(chef_run)
31
+ expect(subject.description).to eq('include any recipe')
32
+ end
33
+ end
34
+
35
+ describe '#matches?' do
36
+ context 'when 0 recipes are included' do
37
+ let(:loaded_recipes) { %w(one) }
38
+
39
+ it 'returns false' do
40
+ expect(subject.matches?(chef_run)).to be false
41
+ end
42
+ end
43
+
44
+ context 'when at least one recipe is included' do
45
+ let(:loaded_recipes) { %w(one two) }
46
+
47
+ it 'returns true' do
48
+ expect(subject.matches?(chef_run)).to be true
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.0
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Crump
8
8
  - Seth Vargo
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-27 00:00:00.000000000 Z
12
+ date: 2020-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -17,28 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '13'
20
+ version: '14'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '13'
27
+ version: '14'
28
28
  - !ruby/object:Gem::Dependency
29
- name: fauxhai
29
+ name: chef-cli
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '6.11'
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '6.11'
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: fauxhai-ng
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '7.5'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '7.5'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rspec
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +86,7 @@ files:
72
86
  - lib/chefspec/api/core.rb
73
87
  - lib/chefspec/api/described.rb
74
88
  - lib/chefspec/api/do_nothing.rb
89
+ - lib/chefspec/api/include_any_recipe.rb
75
90
  - lib/chefspec/api/include_recipe.rb
76
91
  - lib/chefspec/api/link.rb
77
92
  - lib/chefspec/api/notifications.rb
@@ -104,11 +119,13 @@ files:
104
119
  - lib/chefspec/extensions/chef/resource/freebsd_package.rb
105
120
  - lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb
106
121
  - lib/chefspec/extensions/chef/securable.rb
122
+ - lib/chefspec/extensions/ohai/system.rb
107
123
  - lib/chefspec/file_cache_path_proxy.rb
108
124
  - lib/chefspec/formatter.rb
109
125
  - lib/chefspec/librarian.rb
110
126
  - lib/chefspec/matchers.rb
111
127
  - lib/chefspec/matchers/do_nothing_matcher.rb
128
+ - lib/chefspec/matchers/include_any_recipe_matcher.rb
112
129
  - lib/chefspec/matchers/include_recipe_matcher.rb
113
130
  - lib/chefspec/matchers/link_to_matcher.rb
114
131
  - lib/chefspec/matchers/notifications_matcher.rb
@@ -147,6 +164,7 @@ files:
147
164
  - spec/unit/expect_exception_spec.rb
148
165
  - spec/unit/macros_spec.rb
149
166
  - spec/unit/matchers/do_nothing_matcher.rb
167
+ - spec/unit/matchers/include_any_recipe_matcher_spec.rb
150
168
  - spec/unit/matchers/include_recipe_matcher_spec.rb
151
169
  - spec/unit/matchers/link_to_matcher_spec.rb
152
170
  - spec/unit/matchers/notifications_matcher_spec.rb
@@ -183,7 +201,7 @@ homepage: https://github.com/chefspec/chefspec
183
201
  licenses:
184
202
  - MIT
185
203
  metadata: {}
186
- post_install_message:
204
+ post_install_message:
187
205
  rdoc_options: []
188
206
  require_paths:
189
207
  - lib
@@ -191,15 +209,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
209
  requirements:
192
210
  - - ">="
193
211
  - !ruby/object:Gem::Version
194
- version: '2.3'
212
+ version: '2.4'
195
213
  required_rubygems_version: !ruby/object:Gem::Requirement
196
214
  requirements:
197
215
  - - ">="
198
216
  - !ruby/object:Gem::Version
199
217
  version: '0'
200
218
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
219
+ rubygems_version: 3.1.2
220
+ signing_key:
203
221
  specification_version: 4
204
222
  summary: Write RSpec examples and generate coverage reports for Chef recipes!
205
223
  test_files: []