chefspec 9.1.0 → 9.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +16 -9
- data/Rakefile +60 -52
- data/chefspec.gemspec +20 -20
- 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 +22 -19
- data/lib/chefspec/api.rb +14 -14
- data/lib/chefspec/berkshelf.rb +4 -4
- data/lib/chefspec/cacher.rb +2 -2
- data/lib/chefspec/coverage/filters.rb +18 -15
- data/lib/chefspec/coverage.rb +35 -40
- 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/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/freebsd_package.rb +2 -1
- data/lib/chefspec/extensions/chef/resource.rb +18 -12
- data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +21 -1
- data/lib/chefspec/extensions/chef/securable.rb +1 -1
- data/lib/chefspec/extensions/ohai/system.rb +11 -0
- data/lib/chefspec/extensions.rb +14 -13
- data/lib/chefspec/file_cache_path_proxy.rb +3 -3
- data/lib/chefspec/formatter.rb +15 -3
- data/lib/chefspec/librarian.rb +7 -6
- 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/matchers.rb +9 -9
- 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 +27 -25
- 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 +4 -4
- data/lib/chefspec.rb +29 -29
- 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 +10 -11
- data/lib/chefspec/extensions/.DS_Store +0 -0
- data/lib/chefspec/extensions/chef/.DS_Store +0 -0
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
|
@@ -122,9 +123,8 @@ module ChefSpec
|
|
122
123
|
require "chef_zero/data_store/memory_store_v2"
|
123
124
|
ChefZero::DataStore::MemoryStoreV2.new
|
124
125
|
when :on_disk
|
125
|
-
require "tmpdir"
|
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/lib/chefspec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rspec"
|
2
2
|
|
3
3
|
module ChefSpec
|
4
4
|
#
|
@@ -25,7 +25,7 @@ module ChefSpec
|
|
25
25
|
# @return [Pathname]
|
26
26
|
#
|
27
27
|
def root
|
28
|
-
@root ||= Pathname.new(File.expand_path(
|
28
|
+
@root ||= Pathname.new(File.expand_path("..", __dir__))
|
29
29
|
end
|
30
30
|
module_function :root
|
31
31
|
|
@@ -42,34 +42,34 @@ module ChefSpec
|
|
42
42
|
module_function :matchers
|
43
43
|
end
|
44
44
|
|
45
|
-
require_relative
|
45
|
+
require_relative "chefspec/extensions"
|
46
46
|
|
47
|
-
require_relative
|
47
|
+
require_relative "chefspec/mixins/normalize"
|
48
48
|
|
49
|
-
require_relative
|
50
|
-
require_relative
|
51
|
-
require_relative
|
52
|
-
require_relative
|
53
|
-
require_relative
|
54
|
-
require_relative
|
55
|
-
require_relative
|
56
|
-
require_relative
|
57
|
-
require_relative
|
58
|
-
require_relative
|
49
|
+
require_relative "chefspec/stubs/command_registry"
|
50
|
+
require_relative "chefspec/stubs/command_stub"
|
51
|
+
require_relative "chefspec/stubs/data_bag_item_registry"
|
52
|
+
require_relative "chefspec/stubs/data_bag_item_stub"
|
53
|
+
require_relative "chefspec/stubs/data_bag_registry"
|
54
|
+
require_relative "chefspec/stubs/data_bag_stub"
|
55
|
+
require_relative "chefspec/stubs/registry"
|
56
|
+
require_relative "chefspec/stubs/stub"
|
57
|
+
require_relative "chefspec/stubs/search_registry"
|
58
|
+
require_relative "chefspec/stubs/search_stub"
|
59
59
|
|
60
|
-
require_relative
|
61
|
-
require_relative
|
62
|
-
require_relative
|
63
|
-
require_relative
|
64
|
-
require_relative
|
65
|
-
require_relative
|
66
|
-
require_relative
|
67
|
-
require_relative
|
68
|
-
require_relative
|
69
|
-
require_relative
|
70
|
-
require_relative
|
71
|
-
require_relative
|
72
|
-
require_relative
|
73
|
-
require_relative
|
60
|
+
require_relative "chefspec/api"
|
61
|
+
require_relative "chefspec/cacher"
|
62
|
+
require_relative "chefspec/coverage"
|
63
|
+
require_relative "chefspec/errors"
|
64
|
+
require_relative "chefspec/expect_exception"
|
65
|
+
require_relative "chefspec/formatter"
|
66
|
+
require_relative "chefspec/matchers"
|
67
|
+
require_relative "chefspec/renderer"
|
68
|
+
require_relative "chefspec/rspec"
|
69
|
+
require_relative "chefspec/server_runner"
|
70
|
+
require_relative "chefspec/solo_runner"
|
71
|
+
require_relative "chefspec/runner"
|
72
|
+
require_relative "chefspec/util"
|
73
|
+
require_relative "chefspec/version"
|
74
74
|
|
75
|
-
require_relative
|
75
|
+
require_relative "chefspec/deprecations"
|
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
|