chefspec 9.0.0 → 9.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chefspec/api.rb +2 -0
- data/lib/chefspec/api/include_any_recipe.rb +24 -0
- data/lib/chefspec/api/stubs_for.rb +1 -1
- data/lib/chefspec/extensions/chef/provider.rb +1 -1
- data/lib/chefspec/extensions/chef/resource.rb +1 -1
- data/lib/chefspec/matchers.rb +1 -0
- data/lib/chefspec/matchers/include_any_recipe_matcher.rb +51 -0
- data/lib/chefspec/runner.rb +1 -1
- data/lib/chefspec/version.rb +1 -1
- data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +52 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c39db8c598b7a40e7fd080c65db3a073a1e8e95f59a2628682587e5de4db56
|
4
|
+
data.tar.gz: a0bc37df1322446f83af4488fa1def9124d821478c0364a40fcce138c10f63cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354c875c5eb0890aea76c9bb7593dfec11d122157c42ca79842ff8a4264766e6a230fb57a14dfdd6c87887e7c4ba147ee388465e5c2b1fa782ed77a912145844
|
7
|
+
data.tar.gz: 64ff73a7906b1e4ba085a9d5d9182903de2965c9ea4c979ad95363b45677d083868e0f64c30c2637ee7beed85333d309cbe42c26024c6fc7fddc0f6b3b08861d
|
data/lib/chefspec/api.rb
CHANGED
@@ -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.
|
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)
|
data/lib/chefspec/matchers.rb
CHANGED
@@ -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
|
data/lib/chefspec/runner.rb
CHANGED
data/lib/chefspec/version.rb
CHANGED
@@ -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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Crump
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/chefspec/api/core.rb
|
87
87
|
- lib/chefspec/api/described.rb
|
88
88
|
- lib/chefspec/api/do_nothing.rb
|
89
|
+
- lib/chefspec/api/include_any_recipe.rb
|
89
90
|
- lib/chefspec/api/include_recipe.rb
|
90
91
|
- lib/chefspec/api/link.rb
|
91
92
|
- lib/chefspec/api/notifications.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- lib/chefspec/librarian.rb
|
124
125
|
- lib/chefspec/matchers.rb
|
125
126
|
- lib/chefspec/matchers/do_nothing_matcher.rb
|
127
|
+
- lib/chefspec/matchers/include_any_recipe_matcher.rb
|
126
128
|
- lib/chefspec/matchers/include_recipe_matcher.rb
|
127
129
|
- lib/chefspec/matchers/link_to_matcher.rb
|
128
130
|
- lib/chefspec/matchers/notifications_matcher.rb
|
@@ -161,6 +163,7 @@ files:
|
|
161
163
|
- spec/unit/expect_exception_spec.rb
|
162
164
|
- spec/unit/macros_spec.rb
|
163
165
|
- spec/unit/matchers/do_nothing_matcher.rb
|
166
|
+
- spec/unit/matchers/include_any_recipe_matcher_spec.rb
|
164
167
|
- spec/unit/matchers/include_recipe_matcher_spec.rb
|
165
168
|
- spec/unit/matchers/link_to_matcher_spec.rb
|
166
169
|
- spec/unit/matchers/notifications_matcher_spec.rb
|