chefspec 9.2.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.
- 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 +14 -14
- data/lib/chefspec/api/core.rb +3 -3
- data/lib/chefspec/api/described.rb +3 -5
- data/lib/chefspec/api/stubs.rb +2 -2
- data/lib/chefspec/api/stubs_for.rb +12 -12
- 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 -14
- 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 +14 -9
- data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
- data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +12 -1
- data/lib/chefspec/extensions/chef/securable.rb +1 -1
- data/lib/chefspec/extensions/ohai/system.rb +1 -1
- data/lib/chefspec/file_cache_path_proxy.rb +3 -3
- data/lib/chefspec/formatter.rb +3 -3
- data/lib/chefspec/librarian.rb +7 -6
- data/lib/chefspec/matchers.rb +9 -9
- data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
- data/lib/chefspec/matchers/include_any_recipe_matcher.rb +4 -4
- 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/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 +3 -3
- 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 +23 -23
- 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 +6 -6
data/lib/chefspec/util.rb
CHANGED
@@ -14,10 +14,10 @@ module ChefSpec
|
|
14
14
|
def underscore(string)
|
15
15
|
string
|
16
16
|
.to_s
|
17
|
-
.gsub(/::/,
|
18
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
19
|
-
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
20
|
-
.tr(
|
17
|
+
.gsub(/::/, "/")
|
18
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
19
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
20
|
+
.tr("-", "_")
|
21
21
|
.downcase
|
22
22
|
end
|
23
23
|
|
@@ -32,8 +32,8 @@ module ChefSpec
|
|
32
32
|
def camelize(string)
|
33
33
|
string
|
34
34
|
.to_s
|
35
|
-
.split(
|
36
|
-
.map
|
35
|
+
.split("_")
|
36
|
+
.map(&:capitalize)
|
37
37
|
.join
|
38
38
|
end
|
39
39
|
|
@@ -49,7 +49,7 @@ module ChefSpec
|
|
49
49
|
length = options[:length] || 30
|
50
50
|
|
51
51
|
if string.length > length
|
52
|
-
string[0..length-3] +
|
52
|
+
string[0..length - 3] + "..."
|
53
53
|
else
|
54
54
|
string
|
55
55
|
end
|
data/lib/chefspec/version.rb
CHANGED
data/lib/chefspec/zero_server.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "chef_zero/server"
|
2
2
|
|
3
3
|
module ChefSpec
|
4
4
|
# Rather than create a ChefZero instance per test case, simply create one
|
@@ -56,7 +56,7 @@ module ChefSpec
|
|
56
56
|
port: RSpec.configuration.server_runner_port,
|
57
57
|
|
58
58
|
# Set the data store
|
59
|
-
data_store: data_store(RSpec.configuration.server_runner_data_store)
|
59
|
+
data_store: data_store(RSpec.configuration.server_runner_data_store)
|
60
60
|
)
|
61
61
|
@cookbooks_uploaded = false
|
62
62
|
@data_loaded = {}
|
@@ -74,6 +74,7 @@ module ChefSpec
|
|
74
74
|
#
|
75
75
|
def upload_cookbooks!
|
76
76
|
return if @cookbooks_uploaded
|
77
|
+
|
77
78
|
loader = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
|
78
79
|
loader.load_cookbooks
|
79
80
|
cookbook_uploader_for(loader).upload_cookbooks
|
@@ -124,7 +125,6 @@ module ChefSpec
|
|
124
125
|
when :on_disk
|
125
126
|
require "tmpdir" unless defined?(Dir.mktmpdir)
|
126
127
|
require "chef_zero/data_store/raw_file_store"
|
127
|
-
tmpdir = Dir.mktmpdir
|
128
128
|
ChefZero::DataStore::RawFileStore.new(Dir.mktmpdir)
|
129
129
|
else
|
130
130
|
raise ArgumentError, ":#{option} is not a valid server_runner_data_store option. Please use either :in_memory or :on_disk."
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/hash.rb
CHANGED
@@ -11,9 +11,9 @@ class Hash
|
|
11
11
|
# Monkey-patch to allow mash-style look ups for tests
|
12
12
|
#
|
13
13
|
def method_missing(m, *args, &block)
|
14
|
-
if
|
14
|
+
if key?(m.to_sym)
|
15
15
|
self[m.to_sym]
|
16
|
-
elsif
|
16
|
+
elsif key?(m.to_s)
|
17
17
|
self[m.to_s]
|
18
18
|
else
|
19
19
|
super
|
@@ -26,7 +26,7 @@ class Hash
|
|
26
26
|
# @see Hash#respond_to?
|
27
27
|
#
|
28
28
|
def respond_to?(m, include_private = false)
|
29
|
-
if
|
29
|
+
if key?(m.to_sym) || key?(m.to_s)
|
30
30
|
true
|
31
31
|
else
|
32
32
|
super
|
data/spec/unit/cacher_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "chefspec/cacher"
|
3
3
|
|
4
4
|
describe ChefSpec::Cacher do
|
5
5
|
let(:klass) do
|
@@ -7,7 +7,7 @@ describe ChefSpec::Cacher do
|
|
7
7
|
extend ChefSpec::Cacher
|
8
8
|
|
9
9
|
def self.metadata
|
10
|
-
{ parent_example_group: { location:
|
10
|
+
{ parent_example_group: { location: "spec" } }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -17,23 +17,23 @@ describe ChefSpec::Cacher do
|
|
17
17
|
|
18
18
|
before(:each) { described_class.class_variable_set(:@@cache, {}) unless preserve_cache }
|
19
19
|
|
20
|
-
describe
|
21
|
-
it
|
20
|
+
describe "cached" do
|
21
|
+
it "lazily defines the results for the cache" do
|
22
22
|
klass.cached(:chef_run)
|
23
23
|
expect(klass).to be_method_defined(:chef_run)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it "adds the item to the cache when called" do
|
27
27
|
runner = double(:runner)
|
28
28
|
klass.cached(:chef_run) { runner }
|
29
29
|
klass.new.chef_run
|
30
30
|
|
31
|
-
expect(cache[Thread.current.object_id]).to have_key(
|
32
|
-
expect(cache[Thread.current.object_id][
|
31
|
+
expect(cache[Thread.current.object_id]).to have_key("spec.chef_run")
|
32
|
+
expect(cache[Thread.current.object_id]["spec.chef_run"]).to eq(runner)
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
36
|
-
it
|
35
|
+
context "when multithreaded environment" do
|
36
|
+
it "is thread safe" do
|
37
37
|
(1..2).each do |n|
|
38
38
|
Thread.new do
|
39
39
|
klass.cached(:chef_run) { n }
|
@@ -43,14 +43,14 @@ describe ChefSpec::Cacher do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context
|
46
|
+
context "when example groups are defined by looping" do
|
47
47
|
let(:preserve_cache) { true }
|
48
48
|
|
49
|
-
|
49
|
+
%w{first second third}.each do |iteration|
|
50
50
|
context "on the #{iteration} iteration" do
|
51
|
-
context
|
51
|
+
context "in caching context" do
|
52
52
|
cached(:cached_iteration) { iteration }
|
53
|
-
it
|
53
|
+
it "caches the iteration for this context" do
|
54
54
|
expect(cached_iteration).to eq iteration
|
55
55
|
end
|
56
56
|
end
|
@@ -59,12 +59,12 @@ describe ChefSpec::Cacher do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
describe
|
63
|
-
it
|
62
|
+
describe "cached!" do
|
63
|
+
it "loads the value at runtime" do
|
64
64
|
expect(klass).to receive(:cached).with(:chef_run).once
|
65
65
|
expect(klass).to receive(:before).once
|
66
66
|
|
67
|
-
klass.cached!(:chef_run) {
|
67
|
+
klass.cached!(:chef_run) {}
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
# Note: These specs don't use Berkshelf code directly as this project doesn't
|
4
4
|
# have a direct dependency on Berkshelf and loading it would impact the
|
@@ -6,51 +6,51 @@ require 'spec_helper'
|
|
6
6
|
# a standin for Berkshelf to exercise the `#matches?` behavior.
|
7
7
|
describe ChefSpec::Coverage::BerkshelfFilter do
|
8
8
|
let(:dependencies) do
|
9
|
-
[double(
|
9
|
+
[double("Berkshelf::Dependency", metadata?: true, name: "cookbookery")]
|
10
10
|
end
|
11
|
-
let(:berksfile) { double(
|
12
|
-
let(:resource) { Chef::Resource.new(
|
11
|
+
let(:berksfile) { double("Berkshelf::Berksfile", dependencies: dependencies) }
|
12
|
+
let(:resource) { Chef::Resource.new("theone") }
|
13
13
|
subject { described_class.new(berksfile) }
|
14
14
|
|
15
|
-
describe
|
16
|
-
it
|
15
|
+
describe "#matches?" do
|
16
|
+
it "returns truthy if resource source_line is nil" do
|
17
17
|
expect(subject.matches?(resource)).to be_truthy
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
it
|
20
|
+
context "when resource#source_line is under target cookbook" do
|
21
|
+
it "normal unix path returns truthy" do
|
22
22
|
resource.source_line =
|
23
|
-
|
23
|
+
"/path/to/cookbooks/nope/recipes/default.rb:22"
|
24
24
|
expect(subject.matches?(resource)).to be_truthy
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "normal windows path returns truthy" do
|
28
28
|
resource.source_line =
|
29
29
|
'C:\\path\\to\\cookbooks\\nope\\recipes\\default.rb:22'
|
30
30
|
expect(subject.matches?(resource)).to be_truthy
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it "mixed windows path returns truthy" do
|
34
34
|
resource.source_line =
|
35
35
|
'C:\\path\\to\\cookbooks/nope/recipes/default.rb:22'
|
36
36
|
expect(subject.matches?(resource)).to be_truthy
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
41
|
-
it
|
40
|
+
context "when resource#source_line is not under target cookbook" do
|
41
|
+
it "normal unix path returns falsey" do
|
42
42
|
resource.source_line =
|
43
|
-
|
43
|
+
"/path/to/cookbooks/cookbookery/recipes/default.rb:22"
|
44
44
|
expect(subject.matches?(resource)).to be_falsey
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it "normal windows path returns falsey" do
|
48
48
|
resource.source_line =
|
49
49
|
'C:\\path\\to\\cookbooks\\cookbookery\\recipes\\default.rb:22'
|
50
50
|
expect(subject.matches?(resource)).to be_falsey
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "mixed windows path returns falsey" do
|
54
54
|
resource.source_line =
|
55
55
|
'C:\\path\\to\\cookbooks/cookbookery/recipes/default.rb:22'
|
56
56
|
expect(subject.matches?(resource)).to be_falsey
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChefSpec::Runner do
|
4
4
|
before do
|
@@ -8,12 +8,12 @@ describe ChefSpec::Runner do
|
|
8
8
|
allow(ChefSpec::Runner).to receive(:deprecated)
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe "#define_runner_method" do
|
12
12
|
before do
|
13
13
|
allow(ChefSpec).to receive(:define_matcher)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "prints a deprecation" do
|
17
17
|
expect(ChefSpec::Runner).to receive(:deprecated)
|
18
18
|
.with("`ChefSpec::Runner.define_runner_method' is deprecated."\
|
19
19
|
" It is being used in the my_custom_resource resource matcher." \
|
@@ -21,7 +21,7 @@ describe ChefSpec::Runner do
|
|
21
21
|
ChefSpec::Runner.define_runner_method(:my_custom_resource)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "calls ChefSpec#define_matcher" do
|
25
25
|
expect(ChefSpec).to receive(:define_matcher).with(:my_custom_resource).once
|
26
26
|
ChefSpec::Runner.define_runner_method(:my_custom_resource)
|
27
27
|
end
|
@@ -34,19 +34,18 @@ describe ChefSpec::Server do
|
|
34
34
|
allow(ChefSpec::Server).to receive(:deprecated)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "prints a deprecation for any method called" do
|
38
38
|
expect(ChefSpec::Server).to receive(:deprecated)
|
39
39
|
.with("`ChefSpec::Server.any_method' is deprecated. There is no longer" \
|
40
40
|
" a global Chef Server instance. Please use a ChefSpec::SoloRunner" \
|
41
|
-
" instead. More documentation can be found in the ChefSpec README."
|
42
|
-
)
|
41
|
+
" instead. More documentation can be found in the ChefSpec README.")
|
43
42
|
expect {
|
44
43
|
ChefSpec::Server.any_method
|
45
44
|
}.to raise_error(ChefSpec::Error::NoConversionError)
|
46
45
|
end
|
47
46
|
|
48
|
-
it
|
49
|
-
expect{ChefSpec::Server.any_method}
|
47
|
+
it "raises non-conversion error for any method called" do
|
48
|
+
expect { ChefSpec::Server.any_method }
|
50
49
|
.to raise_error(ChefSpec::Error::NoConversionError)
|
51
50
|
end
|
52
51
|
|
data/spec/unit/errors_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module ChefSpec::Error
|
4
4
|
describe CommandNotStubbed do
|
5
|
-
let(:instance) { described_class.new(args: [
|
5
|
+
let(:instance) { described_class.new(args: ["cat"]) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "raises an exception with the correct message" do
|
8
8
|
instance
|
9
|
-
expect { raise instance }.to raise_error { |error|
|
9
|
+
expect { raise instance }.to( raise_error { |error|
|
10
10
|
expect(error).to be_a(described_class)
|
11
|
-
expect(error.message).to eq <<-EOH.gsub(/^ {10}/,
|
11
|
+
expect(error.message).to eq <<-EOH.gsub(/^ {10}/, "")
|
12
12
|
Executing a real command is disabled. Unregistered command:
|
13
13
|
|
14
14
|
command("cat")
|
@@ -17,32 +17,32 @@ module ChefSpec::Error
|
|
17
17
|
|
18
18
|
stub_command("cat").and_return(...)
|
19
19
|
EOH
|
20
|
-
}
|
20
|
+
})
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe CookbookPathNotFound do
|
25
25
|
let(:instance) { described_class.new }
|
26
26
|
|
27
|
-
it
|
28
|
-
expect { raise instance }.to
|
27
|
+
it "raises an exception with the correct message" do
|
28
|
+
expect { raise instance }.to(raise_error { |error|
|
29
29
|
expect(error).to be_a(described_class)
|
30
|
-
expect(error.message).to eq <<-EOH.gsub(/^ {10}/,
|
30
|
+
expect(error.message).to eq <<-EOH.gsub(/^ {10}/, "")
|
31
31
|
I could not find or infer a cookbook_path from your current working directory.
|
32
32
|
Please make sure you put your specs (tests) under a directory named 'spec' or
|
33
33
|
manually set the cookbook path in the RSpec configuration.
|
34
34
|
EOH
|
35
|
-
}
|
35
|
+
})
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe GemLoadError do
|
40
|
-
let(:instance) { described_class.new(gem:
|
40
|
+
let(:instance) { described_class.new(gem: "bacon", name: "bacon") }
|
41
41
|
|
42
|
-
it
|
43
|
-
expect { raise instance }.to raise_error { |error|
|
42
|
+
it "raises an exception with the correct message" do
|
43
|
+
expect { raise instance }.to( raise_error { |error|
|
44
44
|
expect(error).to be_a(described_class)
|
45
|
-
expect(error.message).to eq <<-EOH.gsub(/^ {10}/,
|
45
|
+
expect(error.message).to eq <<-EOH.gsub(/^ {10}/, "")
|
46
46
|
I could not load the 'bacon' gem! You must have the gem installed
|
47
47
|
on your local system before you can use the bacon plugin.
|
48
48
|
You can install bacon by running:
|
@@ -51,7 +51,7 @@ module ChefSpec::Error
|
|
51
51
|
|
52
52
|
or add bacon to your Gemfile and run the `bundle` command to install.
|
53
53
|
EOH
|
54
|
-
}
|
54
|
+
})
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChefSpec::ExpectException do
|
4
|
-
context
|
4
|
+
context "when there have been no `raise_error` matchers" do
|
5
5
|
subject { described_class.new(Exception) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "does not match" do
|
8
8
|
allow(RSpec::Matchers::BuiltIn::RaiseError).to receive(:last_run).and_return(nil)
|
9
9
|
expect(subject.expected?).to be_falsy
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
13
|
+
context "when the last error does not match the expected type" do
|
14
14
|
subject { described_class.new(RuntimeError) }
|
15
15
|
|
16
|
-
it
|
17
|
-
last_error = double(
|
16
|
+
it "does not match" do
|
17
|
+
last_error = double("last error", last_error_for_chefspec: ArgumentError)
|
18
18
|
allow(RSpec::Matchers::BuiltIn::RaiseError).to receive(:last_run).and_return(last_error)
|
19
19
|
expect(subject.expected?).to be_falsy
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
23
|
+
context "when the last error matches the expected type" do
|
24
24
|
subject { described_class.new(RuntimeError) }
|
25
25
|
|
26
|
-
it
|
27
|
-
last_error = double(
|
26
|
+
it "does not match" do
|
27
|
+
last_error = double("last error", last_error_for_chefspec: RuntimeError)
|
28
28
|
allow(RSpec::Matchers::BuiltIn::RaiseError).to receive(:last_run).and_return(last_error)
|
29
29
|
expect(subject.expected?).to be_truthy
|
30
30
|
end
|
data/spec/unit/macros_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChefSpec::API::Stubs do
|
4
|
-
describe
|
5
|
-
let(:command_stub) { double(
|
4
|
+
describe "#stub_command" do
|
5
|
+
let(:command_stub) { double("command") }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "adds the command to the command registry" do
|
8
8
|
allow(ChefSpec::Stubs::CommandStub).to receive(:new).and_return(command_stub)
|
9
9
|
stub_command('echo "hello"')
|
10
10
|
|
@@ -12,21 +12,21 @@ describe ChefSpec::API::Stubs do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
16
|
-
let(:search_stub) { double(
|
15
|
+
describe "#stub_search" do
|
16
|
+
let(:search_stub) { double("search") }
|
17
17
|
|
18
|
-
it
|
18
|
+
it "adds the query to the search registry" do
|
19
19
|
allow(ChefSpec::Stubs::SearchStub).to receive(:new).and_return(search_stub)
|
20
|
-
stub_search(:node,
|
20
|
+
stub_search(:node, "*:*")
|
21
21
|
|
22
22
|
expect(ChefSpec::Stubs::SearchRegistry.stubs).to include(search_stub)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
let(:data_bag_stub) { double(
|
26
|
+
describe "#stub_data_bag" do
|
27
|
+
let(:data_bag_stub) { double("data_bag") }
|
28
28
|
|
29
|
-
it
|
29
|
+
it "adds the query to the data_bag registry" do
|
30
30
|
allow(ChefSpec::Stubs::DataBagStub).to receive(:new).and_return(data_bag_stub)
|
31
31
|
stub_data_bag(:users)
|
32
32
|
|
@@ -34,84 +34,84 @@ describe ChefSpec::API::Stubs do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
let(:data_bag_item_stub) { double(
|
37
|
+
describe "#stub_data_bag_item" do
|
38
|
+
let(:data_bag_item_stub) { double("data_bag_item") }
|
39
39
|
|
40
|
-
it
|
40
|
+
it "adds the query to the data_bag_item registry" do
|
41
41
|
allow(ChefSpec::Stubs::DataBagItemStub).to receive(:new).and_return(data_bag_item_stub)
|
42
|
-
stub_data_bag_item(:users,
|
42
|
+
stub_data_bag_item(:users, "id")
|
43
43
|
|
44
44
|
expect(ChefSpec::Stubs::DataBagItemRegistry.stubs).to include(data_bag_item_stub)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
49
|
-
it
|
48
|
+
describe "#stub_node" do
|
49
|
+
it "returns a Chef::Node" do
|
50
50
|
expect(stub_node).to be_a(Chef::Node)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "defaults the node name to `node.example`" do
|
54
54
|
node = stub_node
|
55
|
-
expect(node.name).to eq(
|
55
|
+
expect(node.name).to eq("node.example")
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
node = stub_node(
|
60
|
-
expect(node.name).to eq(
|
58
|
+
it "sets the node name when given" do
|
59
|
+
node = stub_node("example.com")
|
60
|
+
expect(node.name).to eq("example.com")
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it "sets the automatic attributes" do
|
64
64
|
node = stub_node
|
65
65
|
expect(node.automatic).to eq(Fauxhai.mock.data)
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
node = stub_node(
|
70
|
-
expect(node[
|
68
|
+
it "sets the automatic attributes with ohai overrides" do
|
69
|
+
node = stub_node("node.example", ohai: { ipaddress: "1.2.3.4" })
|
70
|
+
expect(node["ipaddress"]).to eq("1.2.3.4")
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
node = stub_node(
|
75
|
-
expect(node.automatic).to eq(Fauxhai.mock(platform:
|
73
|
+
it "sets the automatic attributes for a specific platform and version" do
|
74
|
+
node = stub_node("node.example", platform: "ubuntu", version: "18.04")
|
75
|
+
expect(node.automatic).to eq(Fauxhai.mock(platform: "ubuntu", version: "18.04").data)
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
79
|
-
allow(File).to receive(:exist?).with(
|
80
|
-
allow(File).to receive(:read).with(
|
81
|
-
node = stub_node(
|
82
|
-
expect(node[
|
78
|
+
it "sets the automatic attributes from a JSON data path" do
|
79
|
+
allow(File).to receive(:exist?).with("/path/to/json").and_return(true)
|
80
|
+
allow(File).to receive(:read).with("/path/to/json").and_return('{ "ipaddress": "1.2.3.4" }')
|
81
|
+
node = stub_node("node.example", path: "/path/to/json")
|
82
|
+
expect(node["ipaddress"]).to eq("1.2.3.4")
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
85
|
+
it "yields a block" do
|
86
86
|
expect { |block| stub_node(&block) }.to yield_with_args(Chef::Node)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
describe
|
92
|
-
describe
|
93
|
-
describe
|
94
|
-
it
|
95
|
-
expect(described_cookbook).to eq(
|
91
|
+
describe "nginx::source" do
|
92
|
+
describe "#described_cookbook" do
|
93
|
+
describe "nginx::source" do
|
94
|
+
it "returns the name of the cookbook" do
|
95
|
+
expect(described_cookbook).to eq("nginx")
|
96
96
|
end
|
97
97
|
|
98
|
-
context
|
99
|
-
it
|
100
|
-
expect(described_cookbook).to eq(
|
98
|
+
context "in a nested context" do
|
99
|
+
it "still returns the name of the cookbook" do
|
100
|
+
expect(described_cookbook).to eq("nginx")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe
|
107
|
-
describe
|
108
|
-
it
|
109
|
-
expect(described_recipe).to eq(
|
106
|
+
describe "#described_recipe" do
|
107
|
+
describe "nginx::source" do
|
108
|
+
it "returns the cookbook::recipe" do
|
109
|
+
expect(described_recipe).to eq("nginx::source")
|
110
110
|
end
|
111
111
|
|
112
|
-
context
|
113
|
-
it
|
114
|
-
expect(described_recipe).to eq(
|
112
|
+
context "in a nested context" do
|
113
|
+
it "still retrns the cookbook::recipe" do
|
114
|
+
expect(described_recipe).to eq("nginx::source")
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|