chefspec 9.2.1 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) 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 +14 -14
  7. data/lib/chefspec/api/core.rb +3 -3
  8. data/lib/chefspec/api/described.rb +3 -5
  9. data/lib/chefspec/api/stubs.rb +2 -2
  10. data/lib/chefspec/api/stubs_for.rb +12 -12
  11. data/lib/chefspec/berkshelf.rb +4 -4
  12. data/lib/chefspec/cacher.rb +2 -2
  13. data/lib/chefspec/coverage.rb +35 -40
  14. data/lib/chefspec/coverage/filters.rb +18 -15
  15. data/lib/chefspec/deprecations.rb +3 -3
  16. data/lib/chefspec/errors.rb +7 -7
  17. data/lib/chefspec/expect_exception.rb +2 -1
  18. data/lib/chefspec/extensions.rb +14 -14
  19. data/lib/chefspec/extensions/chef/client.rb +3 -3
  20. data/lib/chefspec/extensions/chef/conditional.rb +2 -1
  21. data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +5 -4
  22. data/lib/chefspec/extensions/chef/cookbook_loader.rb +1 -0
  23. data/lib/chefspec/extensions/chef/cookbook_uploader.rb +1 -1
  24. data/lib/chefspec/extensions/chef/data_query.rb +3 -3
  25. data/lib/chefspec/extensions/chef/lwrp_base.rb +1 -0
  26. data/lib/chefspec/extensions/chef/provider.rb +8 -5
  27. data/lib/chefspec/extensions/chef/resource.rb +14 -9
  28. data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
  29. data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +12 -1
  30. data/lib/chefspec/extensions/chef/securable.rb +1 -1
  31. data/lib/chefspec/extensions/ohai/system.rb +1 -1
  32. data/lib/chefspec/file_cache_path_proxy.rb +3 -3
  33. data/lib/chefspec/formatter.rb +3 -3
  34. data/lib/chefspec/librarian.rb +7 -6
  35. data/lib/chefspec/matchers.rb +9 -9
  36. data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
  37. data/lib/chefspec/matchers/include_any_recipe_matcher.rb +4 -4
  38. data/lib/chefspec/matchers/include_recipe_matcher.rb +1 -1
  39. data/lib/chefspec/matchers/link_to_matcher.rb +2 -2
  40. data/lib/chefspec/matchers/notifications_matcher.rb +5 -4
  41. data/lib/chefspec/matchers/render_file_matcher.rb +3 -3
  42. data/lib/chefspec/matchers/resource_matcher.rb +18 -16
  43. data/lib/chefspec/mixins/normalize.rb +1 -1
  44. data/lib/chefspec/policyfile.rb +6 -6
  45. data/lib/chefspec/renderer.rb +4 -4
  46. data/lib/chefspec/rspec.rb +1 -1
  47. data/lib/chefspec/server.rb +1 -1
  48. data/lib/chefspec/server_methods.rb +8 -8
  49. data/lib/chefspec/server_runner.rb +10 -10
  50. data/lib/chefspec/solo_runner.rb +26 -24
  51. data/lib/chefspec/stubs/command_registry.rb +1 -1
  52. data/lib/chefspec/stubs/command_stub.rb +1 -1
  53. data/lib/chefspec/stubs/data_bag_item_registry.rb +1 -1
  54. data/lib/chefspec/stubs/data_bag_item_stub.rb +1 -1
  55. data/lib/chefspec/stubs/data_bag_registry.rb +1 -1
  56. data/lib/chefspec/stubs/data_bag_stub.rb +1 -1
  57. data/lib/chefspec/stubs/registry.rb +1 -1
  58. data/lib/chefspec/stubs/search_registry.rb +2 -2
  59. data/lib/chefspec/stubs/search_stub.rb +2 -2
  60. data/lib/chefspec/util.rb +7 -7
  61. data/lib/chefspec/version.rb +1 -1
  62. data/lib/chefspec/zero_server.rb +3 -3
  63. data/spec/spec_helper.rb +3 -4
  64. data/spec/support/hash.rb +3 -3
  65. data/spec/unit/cacher_spec.rb +17 -17
  66. data/spec/unit/coverage/filters_spec.rb +16 -16
  67. data/spec/unit/deprecations_spec.rb +8 -9
  68. data/spec/unit/errors_spec.rb +15 -15
  69. data/spec/unit/expect_exception_spec.rb +9 -9
  70. data/spec/unit/macros_spec.rb +50 -50
  71. data/spec/unit/matchers/do_nothing_matcher.rb +1 -1
  72. data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +23 -23
  73. data/spec/unit/matchers/include_recipe_matcher_spec.rb +15 -15
  74. data/spec/unit/matchers/link_to_matcher_spec.rb +18 -18
  75. data/spec/unit/matchers/notifications_matcher_spec.rb +15 -16
  76. data/spec/unit/matchers/render_file_matcher_spec.rb +26 -26
  77. data/spec/unit/matchers/resource_matcher_spec.rb +1 -1
  78. data/spec/unit/matchers/state_attrs_matcher_spec.rb +24 -24
  79. data/spec/unit/matchers/subscribes_matcher_spec.rb +27 -29
  80. data/spec/unit/renderer_spec.rb +36 -36
  81. data/spec/unit/server_runner_spec.rb +6 -6
  82. data/spec/unit/solo_runner_spec.rb +69 -69
  83. data/spec/unit/stubs/command_registry_spec.rb +11 -11
  84. data/spec/unit/stubs/command_stub_spec.rb +26 -26
  85. data/spec/unit/stubs/data_bag_item_registry_spec.rb +17 -17
  86. data/spec/unit/stubs/data_bag_item_stub_spec.rb +14 -14
  87. data/spec/unit/stubs/data_bag_registry_spec.rb +16 -16
  88. data/spec/unit/stubs/data_bag_stub_spec.rb +13 -13
  89. data/spec/unit/stubs/registry_spec.rb +9 -9
  90. data/spec/unit/stubs/search_registry_spec.rb +17 -17
  91. data/spec/unit/stubs/search_stub_spec.rb +14 -14
  92. data/spec/unit/stubs/stub_spec.rb +22 -22
  93. 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 { |e| e.capitalize }
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
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '9.2.1'
2
+ VERSION = "9.3.0".freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'chef_zero/server'
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
@@ -1,9 +1,8 @@
1
- require 'chefspec'
2
- require 'support/hash'
3
-
1
+ require "chefspec"
2
+ require "support/hash"
4
3
 
5
4
  ChefSpec::Coverage.start! do
6
- set_template 'table.erb'
5
+ set_template "table.erb"
7
6
  end
8
7
 
9
8
  RSpec.configure do |config|
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 has_key?(m.to_sym)
14
+ if key?(m.to_sym)
15
15
  self[m.to_sym]
16
- elsif has_key?(m.to_s)
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 has_key?(m.to_sym) || has_key?(m.to_s)
29
+ if key?(m.to_sym) || key?(m.to_s)
30
30
  true
31
31
  else
32
32
  super
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'chefspec/cacher'
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: 'spec' } }
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 'cached' do
21
- it 'lazily defines the results for the cache' do
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 'adds the item to the cache when called' do
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('spec.chef_run')
32
- expect(cache[Thread.current.object_id]['spec.chef_run']).to eq(runner)
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 'when multithreaded environment' do
36
- it 'is thread safe' do
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 'when example groups are defined by looping' do
46
+ context "when example groups are defined by looping" do
47
47
  let(:preserve_cache) { true }
48
48
 
49
- ['first', 'second', 'third'].each do |iteration|
49
+ %w{first second third}.each do |iteration|
50
50
  context "on the #{iteration} iteration" do
51
- context 'in caching context' do
51
+ context "in caching context" do
52
52
  cached(:cached_iteration) { iteration }
53
- it 'caches the iteration for this context' do
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 'cached!' do
63
- it 'loads the value at runtime' do
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 'spec_helper'
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('Berkshelf::Dependency', metadata?: true, name: "cookbookery")]
9
+ [double("Berkshelf::Dependency", metadata?: true, name: "cookbookery")]
10
10
  end
11
- let(:berksfile) { double('Berkshelf::Berksfile', dependencies: dependencies) }
12
- let(:resource) { Chef::Resource.new('theone') }
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 '#matches?' do
16
- it 'returns truthy if resource source_line is nil' do
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 'when resource#source_line is under target cookbook' do
21
- it 'normal unix path returns truthy' do
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
- '/path/to/cookbooks/nope/recipes/default.rb:22'
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 'normal windows path returns truthy' do
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 'mixed windows path returns truthy' do
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 'when resource#source_line is not under target cookbook' do
41
- it 'normal unix path returns falsey' do
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
- '/path/to/cookbooks/cookbookery/recipes/default.rb:22'
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 'normal windows path returns falsey' do
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 'mixed windows path returns falsey' do
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 'spec_helper'
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 '#define_runner_method' do
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 'prints a deprecation' do
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 'calls ChefSpec#define_matcher' do
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 'prints a deprecation for any method called' do
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 'raises non-conversion error for any method called' do
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
 
@@ -1,14 +1,14 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module ChefSpec::Error
4
4
  describe CommandNotStubbed do
5
- let(:instance) { described_class.new(args: ['cat']) }
5
+ let(:instance) { described_class.new(args: ["cat"]) }
6
6
 
7
- it 'raises an exception with the correct message' do
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 'raises an exception with the correct message' do
28
- expect { raise instance }.to raise_error { |error|
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: 'bacon', name: 'bacon') }
40
+ let(:instance) { described_class.new(gem: "bacon", name: "bacon") }
41
41
 
42
- it 'raises an exception with the correct message' do
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::ExpectException do
4
- context 'when there have been no `raise_error` matchers' do
4
+ context "when there have been no `raise_error` matchers" do
5
5
  subject { described_class.new(Exception) }
6
6
 
7
- it 'does not match' do
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 'when the last error does not match the expected type' do
13
+ context "when the last error does not match the expected type" do
14
14
  subject { described_class.new(RuntimeError) }
15
15
 
16
- it 'does not match' do
17
- last_error = double('last error', last_error_for_chefspec: ArgumentError)
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 'when the last error matches the expected type' do
23
+ context "when the last error matches the expected type" do
24
24
  subject { described_class.new(RuntimeError) }
25
25
 
26
- it 'does not match' do
27
- last_error = double('last error', last_error_for_chefspec: RuntimeError)
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
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::API::Stubs do
4
- describe '#stub_command' do
5
- let(:command_stub) { double('command') }
4
+ describe "#stub_command" do
5
+ let(:command_stub) { double("command") }
6
6
 
7
- it 'adds the command to the command registry' do
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 '#stub_search' do
16
- let(:search_stub) { double('search') }
15
+ describe "#stub_search" do
16
+ let(:search_stub) { double("search") }
17
17
 
18
- it 'adds the query to the search registry' do
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 '#stub_data_bag' do
27
- let(:data_bag_stub) { double('data_bag') }
26
+ describe "#stub_data_bag" do
27
+ let(:data_bag_stub) { double("data_bag") }
28
28
 
29
- it 'adds the query to the data_bag registry' do
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 '#stub_data_bag_item' do
38
- let(:data_bag_item_stub) { double('data_bag_item') }
37
+ describe "#stub_data_bag_item" do
38
+ let(:data_bag_item_stub) { double("data_bag_item") }
39
39
 
40
- it 'adds the query to the data_bag_item registry' do
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, 'id')
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 '#stub_node' do
49
- it 'returns a Chef::Node' do
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 'defaults the node name to `node.example`' do
53
+ it "defaults the node name to `node.example`" do
54
54
  node = stub_node
55
- expect(node.name).to eq('node.example')
55
+ expect(node.name).to eq("node.example")
56
56
  end
57
57
 
58
- it 'sets the node name when given' do
59
- node = stub_node('example.com')
60
- expect(node.name).to eq('example.com')
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 'sets the automatic attributes' do
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 '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')
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 '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)
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 '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')
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 'yields a block' do
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 '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')
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 'in a nested context' do
99
- it 'still returns the name of the cookbook' do
100
- expect(described_cookbook).to eq('nginx')
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 '#described_recipe' do
107
- describe 'nginx::source' do
108
- it 'returns the cookbook::recipe' do
109
- expect(described_recipe).to eq('nginx::source')
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 'in a nested context' do
113
- it 'still retrns the cookbook::recipe' do
114
- expect(described_recipe).to eq('nginx::source')
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