chefspec 8.0.1 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) 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 +15 -13
  7. data/lib/chefspec/api/core.rb +3 -3
  8. data/lib/chefspec/api/described.rb +3 -5
  9. data/lib/chefspec/api/include_any_recipe.rb +24 -0
  10. data/lib/chefspec/api/stubs.rb +2 -2
  11. data/lib/chefspec/api/stubs_for.rb +23 -20
  12. data/lib/chefspec/berkshelf.rb +4 -4
  13. data/lib/chefspec/cacher.rb +2 -2
  14. data/lib/chefspec/coverage.rb +35 -40
  15. data/lib/chefspec/coverage/filters.rb +18 -15
  16. data/lib/chefspec/deprecations.rb +3 -3
  17. data/lib/chefspec/errors.rb +7 -7
  18. data/lib/chefspec/expect_exception.rb +2 -1
  19. data/lib/chefspec/extensions.rb +14 -13
  20. data/lib/chefspec/extensions/chef/client.rb +3 -3
  21. data/lib/chefspec/extensions/chef/conditional.rb +2 -1
  22. data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +5 -4
  23. data/lib/chefspec/extensions/chef/cookbook_loader.rb +1 -0
  24. data/lib/chefspec/extensions/chef/cookbook_uploader.rb +1 -1
  25. data/lib/chefspec/extensions/chef/data_query.rb +3 -3
  26. data/lib/chefspec/extensions/chef/lwrp_base.rb +1 -0
  27. data/lib/chefspec/extensions/chef/provider.rb +8 -5
  28. data/lib/chefspec/extensions/chef/resource.rb +18 -12
  29. data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +2 -1
  30. data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +21 -1
  31. data/lib/chefspec/extensions/chef/securable.rb +1 -1
  32. data/lib/chefspec/extensions/ohai/system.rb +11 -0
  33. data/lib/chefspec/file_cache_path_proxy.rb +3 -3
  34. data/lib/chefspec/formatter.rb +15 -3
  35. data/lib/chefspec/librarian.rb +7 -6
  36. data/lib/chefspec/matchers.rb +9 -8
  37. data/lib/chefspec/matchers/do_nothing_matcher.rb +15 -15
  38. data/lib/chefspec/matchers/include_any_recipe_matcher.rb +51 -0
  39. data/lib/chefspec/matchers/include_recipe_matcher.rb +1 -1
  40. data/lib/chefspec/matchers/link_to_matcher.rb +2 -2
  41. data/lib/chefspec/matchers/notifications_matcher.rb +5 -4
  42. data/lib/chefspec/matchers/render_file_matcher.rb +3 -3
  43. data/lib/chefspec/matchers/resource_matcher.rb +18 -16
  44. data/lib/chefspec/mixins/normalize.rb +1 -1
  45. data/lib/chefspec/policyfile.rb +6 -6
  46. data/lib/chefspec/renderer.rb +4 -4
  47. data/lib/chefspec/rspec.rb +1 -1
  48. data/lib/chefspec/runner.rb +1 -1
  49. data/lib/chefspec/server.rb +1 -1
  50. data/lib/chefspec/server_methods.rb +8 -8
  51. data/lib/chefspec/server_runner.rb +10 -10
  52. data/lib/chefspec/solo_runner.rb +26 -24
  53. data/lib/chefspec/stubs/command_registry.rb +1 -1
  54. data/lib/chefspec/stubs/command_stub.rb +1 -1
  55. data/lib/chefspec/stubs/data_bag_item_registry.rb +1 -1
  56. data/lib/chefspec/stubs/data_bag_item_stub.rb +1 -1
  57. data/lib/chefspec/stubs/data_bag_registry.rb +1 -1
  58. data/lib/chefspec/stubs/data_bag_stub.rb +1 -1
  59. data/lib/chefspec/stubs/registry.rb +1 -1
  60. data/lib/chefspec/stubs/search_registry.rb +2 -2
  61. data/lib/chefspec/stubs/search_stub.rb +2 -2
  62. data/lib/chefspec/util.rb +7 -7
  63. data/lib/chefspec/version.rb +1 -1
  64. data/lib/chefspec/zero_server.rb +4 -4
  65. data/spec/spec_helper.rb +3 -4
  66. data/spec/support/hash.rb +3 -3
  67. data/spec/unit/cacher_spec.rb +17 -17
  68. data/spec/unit/coverage/filters_spec.rb +16 -16
  69. data/spec/unit/deprecations_spec.rb +8 -9
  70. data/spec/unit/errors_spec.rb +15 -15
  71. data/spec/unit/expect_exception_spec.rb +9 -9
  72. data/spec/unit/macros_spec.rb +50 -50
  73. data/spec/unit/matchers/do_nothing_matcher.rb +1 -1
  74. data/spec/unit/matchers/include_any_recipe_matcher_spec.rb +52 -0
  75. data/spec/unit/matchers/include_recipe_matcher_spec.rb +15 -15
  76. data/spec/unit/matchers/link_to_matcher_spec.rb +18 -18
  77. data/spec/unit/matchers/notifications_matcher_spec.rb +15 -16
  78. data/spec/unit/matchers/render_file_matcher_spec.rb +26 -26
  79. data/spec/unit/matchers/resource_matcher_spec.rb +1 -1
  80. data/spec/unit/matchers/state_attrs_matcher_spec.rb +24 -24
  81. data/spec/unit/matchers/subscribes_matcher_spec.rb +27 -29
  82. data/spec/unit/renderer_spec.rb +36 -36
  83. data/spec/unit/server_runner_spec.rb +6 -6
  84. data/spec/unit/solo_runner_spec.rb +69 -69
  85. data/spec/unit/stubs/command_registry_spec.rb +11 -11
  86. data/spec/unit/stubs/command_stub_spec.rb +26 -26
  87. data/spec/unit/stubs/data_bag_item_registry_spec.rb +17 -17
  88. data/spec/unit/stubs/data_bag_item_stub_spec.rb +14 -14
  89. data/spec/unit/stubs/data_bag_registry_spec.rb +16 -16
  90. data/spec/unit/stubs/data_bag_stub_spec.rb +13 -13
  91. data/spec/unit/stubs/registry_spec.rb +9 -9
  92. data/spec/unit/stubs/search_registry_spec.rb +17 -17
  93. data/spec/unit/stubs/search_stub_spec.rb +14 -14
  94. data/spec/unit/stubs/stub_spec.rb +22 -22
  95. metadata +16 -12
@@ -1,67 +1,67 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::Matchers::RenderFileMatcher do
4
- let(:path) { '/tmp/thing' }
5
- let(:file) { double('file', to: path, to_s: "file[#{path}]", performed_action?: true) }
6
- let(:chef_run) { double('chef run', find_resource: file) }
4
+ let(:path) { "/tmp/thing" }
5
+ let(:file) { double("file", to: path, to_s: "file[#{path}]", performed_action?: true) }
6
+ let(:chef_run) { double("chef run", find_resource: file) }
7
7
  subject { described_class.new(path) }
8
8
 
9
- describe '#with_content' do
10
- it 'accepts do/end syntax' do
9
+ describe "#with_content" do
10
+ it "accepts do/end syntax" do
11
11
  subject.matches?(chef_run)
12
12
  expect(
13
13
  subject.with_content do |content|
14
- 'Does not raise ArgumentError'
14
+ "Does not raise ArgumentError"
15
15
  end.expected_content.first.call
16
- ).to eq('Does not raise ArgumentError')
16
+ ).to eq("Does not raise ArgumentError")
17
17
  end
18
18
  end
19
19
 
20
- describe '#failure_message' do
21
- it 'has the right value' do
20
+ describe "#failure_message" do
21
+ it "has the right value" do
22
22
  subject.matches?(chef_run)
23
23
  expect(subject.failure_message)
24
- .to eq(%Q(expected Chef run to render "#{path}"))
24
+ .to eq(%Q{expected Chef run to render "#{path}"})
25
25
  end
26
26
  end
27
27
 
28
- describe '#failure_message_when_negated' do
29
- it 'has the right value' do
28
+ describe "#failure_message_when_negated" do
29
+ it "has the right value" do
30
30
  subject.matches?(chef_run)
31
31
  expect(subject.failure_message_when_negated)
32
- .to eq(%Q(expected file "#{path}" to not be in Chef run))
32
+ .to eq(%Q{expected file "#{path}" to not be in Chef run})
33
33
  end
34
34
  end
35
35
 
36
- describe '#description' do
37
- it 'has the right value' do
36
+ describe "#description" do
37
+ it "has the right value" do
38
38
  subject.matches?(chef_run)
39
- expect(subject.description).to eq(%Q(render file "#{path}"))
39
+ expect(subject.description).to eq(%Q{render file "#{path}"})
40
40
  end
41
41
 
42
- it 'has the right value when with_content is chained' do
42
+ it "has the right value when with_content is chained" do
43
43
  subject.matches?(chef_run)
44
44
  expect(
45
- subject.with_content('foo').with_content('bar').description
46
- ).to eq(%Q(render file "#{path}" with content "foo" with content "bar"))
45
+ subject.with_content("foo").with_content("bar").description
46
+ ).to eq(%Q{render file "#{path}" with content "foo" with content "bar"})
47
47
  end
48
48
  end
49
49
 
50
- context 'when the file is correct' do
51
- it 'matches' do
50
+ context "when the file is correct" do
51
+ it "matches" do
52
52
  expect(subject.matches?(chef_run)).to be_truthy
53
53
  end
54
54
 
55
- it 'adds the resource to the coverage report' do
55
+ it "adds the resource to the coverage report" do
56
56
  expect(ChefSpec::Coverage).to receive(:cover!).with(file)
57
57
  subject.matches?(chef_run)
58
58
  end
59
59
  end
60
60
 
61
- context 'when the file is not correct' do
62
- it 'does not match' do
61
+ context "when the file is not correct" do
62
+ it "does not match" do
63
63
  allow(chef_run).to receive(:find_resource).and_return(nil)
64
- failure = described_class.new('nope')
64
+ failure = described_class.new("nope")
65
65
  expect(failure.matches?(chef_run)).to be_falsy
66
66
  end
67
67
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::Matchers::ResourceMatcher do
4
4
  pending
@@ -1,22 +1,22 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::Matchers::StateAttrsMatcher do
4
- subject { described_class.new([:a, :b]) }
4
+ subject { described_class.new(%i{a b}) }
5
5
 
6
- context 'when the resource does not exist' do
6
+ context "when the resource does not exist" do
7
7
  let(:resource) { nil }
8
8
  before { subject.matches?(resource) }
9
9
 
10
- it 'does not match' do
10
+ it "does not match" do
11
11
  expect(subject).to_not be_matches(resource)
12
12
  end
13
13
 
14
- it 'has the correct description' do
15
- expect(subject.description).to eq('have state attributes [:a, :b]')
14
+ it "has the correct description" do
15
+ expect(subject.description).to eq("have state attributes [:a, :b]")
16
16
  end
17
17
 
18
- it 'has the correct failure message for should' do
19
- expect(subject.failure_message).to include <<-EOH.gsub(/^ {8}/, '')
18
+ it "has the correct failure message for should" do
19
+ expect(subject.failure_message).to include <<-EOH.gsub(/^ {8}/, "")
20
20
  expected _something_ to have state attributes, but the _something_ you gave me was nil!
21
21
  Ensure the resource exists before making assertions:
22
22
 
@@ -24,8 +24,8 @@ describe ChefSpec::Matchers::StateAttrsMatcher do
24
24
  EOH
25
25
  end
26
26
 
27
- it 'has the correct failure message for should not' do
28
- expect(subject.failure_message_when_negated).to include <<-EOH.gsub(/^ {8}/, '')
27
+ it "has the correct failure message for should not" do
28
+ expect(subject.failure_message_when_negated).to include <<-EOH.gsub(/^ {8}/, "")
29
29
  expected _something_ to not have state attributes, but the _something_ you gave me was nil!
30
30
  Ensure the resource exists before making assertions:
31
31
 
@@ -34,34 +34,34 @@ describe ChefSpec::Matchers::StateAttrsMatcher do
34
34
  end
35
35
  end
36
36
 
37
- context 'when the resource exists' do
38
- let(:klass) { double('class', state_attrs: [:a, :b]) }
39
- let(:resource) { double('resource', class: klass) }
37
+ context "when the resource exists" do
38
+ let(:klass) { double("class", state_attrs: %i{a b}) }
39
+ let(:resource) { double("resource", class: klass) }
40
40
  before { subject.matches?(resource) }
41
41
 
42
- it 'has the correct description' do
43
- expect(subject.description).to eq('have state attributes [:a, :b]')
42
+ it "has the correct description" do
43
+ expect(subject.description).to eq("have state attributes [:a, :b]")
44
44
  end
45
45
 
46
- it 'has the correct failure message for should' do
47
- expect(subject.failure_message).to eq('expected [:a, :b] to equal [:a, :b]')
46
+ it "has the correct failure message for should" do
47
+ expect(subject.failure_message).to eq("expected [:a, :b] to equal [:a, :b]")
48
48
  end
49
49
 
50
- it 'has the correct failure message for should not' do
51
- expect(subject.failure_message_when_negated).to eq('expected [:a, :b] to not equal [:a, :b]')
50
+ it "has the correct failure message for should not" do
51
+ expect(subject.failure_message_when_negated).to eq("expected [:a, :b] to not equal [:a, :b]")
52
52
  end
53
53
 
54
- it 'matches when the state attributes are correct' do
54
+ it "matches when the state attributes are correct" do
55
55
  expect(subject).to be_matches(resource)
56
56
  end
57
57
 
58
- it 'does not match when the state attributes are incorrect' do
59
- allow(klass).to receive(:state_attrs).and_return([:c, :d])
58
+ it "does not match when the state attributes are incorrect" do
59
+ allow(klass).to receive(:state_attrs).and_return(%i{c d})
60
60
  expect(subject).to_not be_matches(resource)
61
61
  end
62
62
 
63
- it 'does not match when partial state attribute are incorrect' do
64
- allow(klass).to receive(:state_attrs).and_return([:b, :c])
63
+ it "does not match when partial state attribute are incorrect" do
64
+ allow(klass).to receive(:state_attrs).and_return(%i{b c})
65
65
  expect(subject).to_not be_matches(resource)
66
66
  end
67
67
  end
@@ -1,65 +1,63 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::Matchers::SubscribesMatcher do
4
- subject { described_class.new('execute[install]') }
5
- let(:runner) { double('runner', find_resource: nil) }
6
- let(:run_context) { double('run_context', node: node) }
7
- let(:node) { double('node', runner: runner) }
4
+ subject { described_class.new("execute[install]") }
5
+ let(:runner) { double("runner", find_resource: nil) }
6
+ let(:run_context) { double("run_context", node: node) }
7
+ let(:node) { double("node", runner: runner) }
8
8
  let(:package) do
9
- double('package',
10
- name: 'package',
11
- to_s: 'package[foo]',
12
- run_context: run_context,
13
- )
9
+ double("package",
10
+ name: "package",
11
+ to_s: "package[foo]",
12
+ run_context: run_context)
14
13
  end
15
14
 
16
- context 'when no resource is found' do
17
- describe '#failure_message' do
18
- it 'has the right value' do
15
+ context "when no resource is found" do
16
+ describe "#failure_message" do
17
+ it "has the right value" do
19
18
  subject.matches?(package)
20
19
  expect(subject.failure_message)
21
- .to include %|expected _something_ to notify "package[foo]", but the _something_ you gave me was nil! If you are running a test like:|
20
+ .to include %{expected _something_ to notify "package[foo]", but the _something_ you gave me was nil! If you are running a test like:}
22
21
  end
23
22
  end
24
23
  end
25
24
 
26
- context 'when the resource exists' do
25
+ context "when the resource exists" do
27
26
  let(:execute) do
28
- double('execute',
29
- name: 'execute',
30
- to_s: 'execute[install]',
27
+ double("execute",
28
+ name: "execute",
29
+ to_s: "execute[install]",
31
30
  immediate_notifications: [],
32
31
  delayed_notifications: [],
33
- before_notifications: []
34
- )
32
+ before_notifications: [])
35
33
  end
36
34
 
37
35
  before do
38
36
  allow(runner).to receive(:find_resource).and_return(execute)
39
37
  end
40
38
 
41
- describe '#failure_message' do
42
- it 'has the right value' do
39
+ describe "#failure_message" do
40
+ it "has the right value" do
43
41
  subject.matches?(package)
44
42
  expect(subject.failure_message)
45
- .to include %|expected "execute[install]" to notify "package[foo]", but did not.|
43
+ .to include %{expected "execute[install]" to notify "package[foo]", but did not.}
46
44
  end
47
45
  end
48
46
 
49
- describe '#failure_message_when_negated' do
50
- it 'has the right value' do
47
+ describe "#failure_message_when_negated" do
48
+ it "has the right value" do
51
49
  subject.matches?(package)
52
50
  expect(subject.failure_message_when_negated)
53
- .to eq %|expected "execute[install]" to not notify "package[foo]", but it did.|
51
+ .to eq %{expected "execute[install]" to not notify "package[foo]", but it did.}
54
52
  end
55
53
  end
56
54
  end
57
55
 
58
- describe '#description' do
59
- it 'has the right value' do
56
+ describe "#description" do
57
+ it "has the right value" do
60
58
  subject.matches?(package)
61
59
  expect(subject.description)
62
- .to eq %|notify "package[foo]"|
60
+ .to eq %{notify "package[foo]"}
63
61
  end
64
62
  end
65
63
  end
@@ -1,69 +1,69 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::Renderer do
4
- describe '.initialize' do
5
- it 'accepts two arguments and assigns their instance variables' do
6
- instance = described_class.new('runner', 'resource')
7
- expect(instance.chef_run).to eq('runner')
8
- expect(instance.resource).to eq('resource')
4
+ describe ".initialize" do
5
+ it "accepts two arguments and assigns their instance variables" do
6
+ instance = described_class.new("runner", "resource")
7
+ expect(instance.chef_run).to eq("runner")
8
+ expect(instance.resource).to eq("resource")
9
9
  end
10
10
  end
11
11
 
12
- let(:chef_run) { double('chef_run', {node: 'node'}) }
13
- let(:resource) { double('resource', {cookbook: 'cookbook', source: 'source', variables: {}}) }
12
+ let(:chef_run) { double("chef_run", { node: "node" }) }
13
+ let(:resource) { double("resource", { cookbook: "cookbook", source: "source", variables: {} }) }
14
14
  subject { described_class.new(chef_run, resource) }
15
15
 
16
- describe '#content' do
16
+ describe "#content" do
17
17
  before do
18
- allow(subject).to receive(:content_from_cookbook_file).and_return('cookbook_file content')
19
- allow(subject).to receive(:content_from_file).and_return('file content')
20
- allow(subject).to receive(:content_from_template).and_return('template content')
18
+ allow(subject).to receive(:content_from_cookbook_file).and_return("cookbook_file content")
19
+ allow(subject).to receive(:content_from_file).and_return("file content")
20
+ allow(subject).to receive(:content_from_template).and_return("template content")
21
21
  end
22
22
 
23
- context 'when the resource is a cookbook_file' do
24
- it 'renders the cookbook_file content' do
25
- allow(resource).to receive(:resource_name).and_return('cookbook_file')
26
- expect(subject.content).to eq('cookbook_file content')
23
+ context "when the resource is a cookbook_file" do
24
+ it "renders the cookbook_file content" do
25
+ allow(resource).to receive(:resource_name).and_return("cookbook_file")
26
+ expect(subject.content).to eq("cookbook_file content")
27
27
  end
28
28
  end
29
29
 
30
- context 'when the resource is a file' do
31
- it 'renders the file content' do
32
- allow(resource).to receive(:resource_name).and_return('file')
33
- expect(subject.content).to eq('file content')
30
+ context "when the resource is a file" do
31
+ it "renders the file content" do
32
+ allow(resource).to receive(:resource_name).and_return("file")
33
+ expect(subject.content).to eq("file content")
34
34
  end
35
35
  end
36
36
 
37
- context 'when the resource is a template' do
38
- it 'renders the template content' do
39
- allow(resource).to receive(:resource_name).and_return('template')
40
- expect(subject.content).to eq('template content')
37
+ context "when the resource is a template" do
38
+ it "renders the template content" do
39
+ allow(resource).to receive(:resource_name).and_return("template")
40
+ expect(subject.content).to eq("template content")
41
41
  end
42
42
  end
43
43
 
44
- context 'when the resource is not a file type' do
45
- it 'returns nil' do
46
- allow(resource).to receive(:resource_name).and_return('service')
44
+ context "when the resource is not a file type" do
45
+ it "returns nil" do
46
+ allow(resource).to receive(:resource_name).and_return("service")
47
47
  expect(subject.content).to be_nil
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
- describe 'content_from_template' do
53
- it 'renders the template by extending modules for rendering paritals within the template' do
52
+ describe "content_from_template" do
53
+ it "renders the template by extending modules for rendering paritals within the template" do
54
54
  cookbook_collection = {}
55
- cookbook_collection['cookbook'] = double('', {preferred_filename_on_disk_location: "/template/location"} )
56
- allow(subject).to receive(:cookbook_collection).with('node').and_return(cookbook_collection)
55
+ cookbook_collection["cookbook"] = double("", { preferred_filename_on_disk_location: "/template/location" } )
56
+ allow(subject).to receive(:cookbook_collection).with("node").and_return(cookbook_collection)
57
57
  allow(subject).to receive(:template_finder)
58
-
58
+
59
59
  allow(resource).to receive(:helper_modules).and_return([Module.new])
60
- allow(resource).to receive(:resource_name).and_return('template')
60
+ allow(resource).to receive(:resource_name).and_return("template")
61
61
 
62
- chef_template_context = double('context', {render_template: 'rendered template content',update: nil})
62
+ chef_template_context = double("context", { render_template: "rendered template content", update: nil })
63
63
  allow(Chef::Mixin::Template::TemplateContext).to receive(:new).and_return(chef_template_context)
64
-
64
+
65
65
  expect(chef_template_context).to receive(:_extend_modules).with(resource.helper_modules)
66
- expect(subject.content).to eq('rendered template content')
66
+ expect(subject.content).to eq("rendered template content")
67
67
  end
68
68
  end
69
69
  end
@@ -1,8 +1,8 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::ServerRunner do
4
- context 'when the RSpec config is set' do
5
- it 'does not create a tmpdir' do
4
+ context "when the RSpec config is set" do
5
+ it "does not create a tmpdir" do
6
6
  allow(RSpec.configuration).to receive(:file_cache_path)
7
7
  .and_return("/foo/bar")
8
8
  expect(ChefSpec::FileCachePathProxy).to_not receive(:instance)
@@ -10,15 +10,15 @@ describe ChefSpec::ServerRunner do
10
10
  end
11
11
  end
12
12
 
13
- context 'when the RSpec config is not set' do
14
- it 'creates and returns a tmpdir' do
13
+ context "when the RSpec config is not set" do
14
+ it "creates and returns a tmpdir" do
15
15
  expect(ChefSpec::FileCachePathProxy).to receive(:instance)
16
16
  .and_call_original
17
17
  described_class.new
18
18
  expect(Chef::Config[:file_cache_path]).to match(/chefspec/)
19
19
  end
20
20
 
21
- it 'uses the same path' do
21
+ it "uses the same path" do
22
22
  val = ChefSpec::FileCachePathProxy.instance.file_cache_path
23
23
  expect(described_class.new.options[:file_cache_path]).to eq(val)
24
24
  expect(described_class.new.options[:file_cache_path]).to eq(val)
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChefSpec::SoloRunner do
4
4
  before do
@@ -7,7 +7,7 @@ describe ChefSpec::SoloRunner do
7
7
  .and_return(true)
8
8
  end
9
9
 
10
- describe '#initialize' do
10
+ describe "#initialize" do
11
11
  let(:windows_caller_stack) do
12
12
  [
13
13
  "C:/cookbooks/Temp/spec/test_spec.rb:11:in `block (2 levels) in <top (required)>'",
@@ -29,22 +29,22 @@ describe ChefSpec::SoloRunner do
29
29
  ]
30
30
  end
31
31
 
32
- it 'defaults the log level to :warn' do
32
+ it "defaults the log level to :warn" do
33
33
  described_class.new
34
34
  expect(Chef::Log.level).to eq(:warn)
35
35
  end
36
36
 
37
- it 'sets the log level' do
37
+ it "sets the log level" do
38
38
  described_class.new(log_level: :error)
39
39
  expect(Chef::Log.level).to eq(:error)
40
40
  end
41
41
 
42
- it 'defaults the cookbook_path to the calling spec' do
42
+ it "defaults the cookbook_path to the calling spec" do
43
43
  described_class.new
44
- expect(Chef::Config.cookbook_path).to eq([File.expand_path('../../../..', __FILE__)])
44
+ expect(Chef::Config.cookbook_path).to eq([File.expand_path("../../..", __dir__)])
45
45
  end
46
46
 
47
- it 'defaults the cookbook_path to the calling spec when using windows paths' do
47
+ it "defaults the cookbook_path to the calling spec when using windows paths" do
48
48
  runner = described_class.new
49
49
  windows_path = runner.instance_exec(windows_caller_stack) { |callstack|
50
50
  calling_cookbook_path({}, callstack)
@@ -55,117 +55,117 @@ describe ChefSpec::SoloRunner do
55
55
  expect(windows_path).to end_with("C:/cookbooks")
56
56
  end
57
57
 
58
- it 'sets the cookbook path' do
59
- described_class.new(cookbook_path: '/tmp/bacon')
60
- expect(Chef::Config.cookbook_path).to eq(['/tmp/bacon'])
58
+ it "sets the cookbook path" do
59
+ described_class.new(cookbook_path: "/tmp/bacon")
60
+ expect(Chef::Config.cookbook_path).to eq(["/tmp/bacon"])
61
61
  end
62
62
 
63
- it 'sets the file cache path' do
64
- described_class.new( file_cache_path: '/tmp/pantoa')
65
- expect(Chef::Config.file_cache_path).to eq('/tmp/pantoa')
63
+ it "sets the file cache path" do
64
+ described_class.new( file_cache_path: "/tmp/pantoa")
65
+ expect(Chef::Config.file_cache_path).to eq("/tmp/pantoa")
66
66
  end
67
67
 
68
- it 'sets the Chef::Config' do
69
- expect(Chef::Config.cache_type).to eq('Memory')
68
+ it "sets the Chef::Config" do
69
+ expect(Chef::Config.cache_type).to eq("Memory")
70
70
  expect(Chef::Config.force_logger).to be_truthy
71
71
  expect(Chef::Config.no_lazy_load).to be_truthy
72
72
  expect(Chef::Config.solo).to be_truthy
73
73
  expect(Chef::Config.use_policyfile).to be_falsey
74
74
  end
75
75
 
76
- it 'yields a block to set node attributes' do
76
+ it "yields a block to set node attributes" do
77
77
  expect { |block| described_class.new({}, &block) }.to yield_with_args(Chef::Node)
78
78
  end
79
79
 
80
- context 'default ohai attributes' do
80
+ context "default ohai attributes" do
81
81
  let(:hash) { described_class.new.node.to_hash }
82
82
 
83
- it 'sets the default attributes' do
84
- expect(hash['os']).to eq('chefspec')
85
- expect(hash['languages']['ruby']['bin_dir']).to eq('/usr/local/bin')
86
- expect(hash['os_version']).to eq('0.6.1')
87
- expect(hash['fqdn']).to eq('chefspec.local')
88
- expect(hash['domain']).to eq('local')
89
- expect(hash['ipaddress']).to eq('127.0.0.1')
90
- expect(hash['hostname']).to eq('chefspec')
91
- expect(hash['kernel']['machine']).to eq('i386')
83
+ it "sets the default attributes" do
84
+ expect(hash["os"]).to eq("chefspec")
85
+ expect(hash["languages"]["ruby"]["bin_dir"]).to eq("/usr/local/bin")
86
+ expect(hash["os_version"]).to eq("0.6.1")
87
+ expect(hash["fqdn"]).to eq("chefspec.local")
88
+ expect(hash["domain"]).to eq("local")
89
+ expect(hash["ipaddress"]).to eq("127.0.0.1")
90
+ expect(hash["hostname"]).to eq("chefspec")
91
+ expect(hash["kernel"]["machine"]).to eq("i386")
92
92
  end
93
93
  end
94
94
 
95
- context 'fauxhai attributes' do
96
- let(:hash) { described_class.new(platform: 'ubuntu', version: '18.04').node.to_hash }
95
+ context "fauxhai attributes" do
96
+ let(:hash) { described_class.new(platform: "ubuntu", version: "18.04").node.to_hash }
97
97
 
98
- it 'sets the attributes from fauxhai' do
99
- expect(hash['os']).to eq('linux')
100
- expect(hash['languages']['ruby']['ruby_bin']).to eq('/usr/local/bin/ruby')
101
- expect(hash['os_version']).to match(/4.15.0-.*-.*/) # avoid failing when fauxhai data changes
102
- expect(hash['fqdn']).to eq('fauxhai.local')
103
- expect(hash['domain']).to eq('local')
104
- expect(hash['ipaddress']).to eq('10.0.0.2')
105
- expect(hash['hostname']).to eq('Fauxhai')
106
- expect(hash['kernel']['machine']).to eq('x86_64')
98
+ it "sets the attributes from fauxhai" do
99
+ expect(hash["os"]).to eq("linux")
100
+ expect(hash["languages"]["ruby"]["ruby_bin"]).to eq("/usr/local/bin/ruby")
101
+ expect(hash["os_version"]).to match(/5.4.0-.*-.*/) # avoid failing when fauxhai data changes
102
+ expect(hash["fqdn"]).to eq("fauxhai.local")
103
+ expect(hash["domain"]).to eq("local")
104
+ expect(hash["ipaddress"]).to eq("10.0.0.2")
105
+ expect(hash["hostname"]).to eq("Fauxhai")
106
+ expect(hash["kernel"]["machine"]).to eq("x86_64")
107
107
  end
108
108
  end
109
109
 
110
- context 'RSpec global configuration' do
110
+ context "RSpec global configuration" do
111
111
  before do
112
- allow(RSpec.configuration).to receive(:cookbook_path).and_return('./path')
113
- allow(RSpec.configuration).to receive(:environment_path).and_return('./env-path')
114
- allow(RSpec.configuration).to receive(:file_cache_path).and_return('./file-cache-path')
112
+ allow(RSpec.configuration).to receive(:cookbook_path).and_return("./path")
113
+ allow(RSpec.configuration).to receive(:environment_path).and_return("./env-path")
114
+ allow(RSpec.configuration).to receive(:file_cache_path).and_return("./file-cache-path")
115
115
  allow(RSpec.configuration).to receive(:log_level).and_return(:fatal)
116
- allow(RSpec.configuration).to receive(:path).and_return('ohai.json')
117
- allow(RSpec.configuration).to receive(:platform).and_return('ubuntu')
118
- allow(RSpec.configuration).to receive(:version).and_return('12.04')
116
+ allow(RSpec.configuration).to receive(:path).and_return("ohai.json")
117
+ allow(RSpec.configuration).to receive(:platform).and_return("ubuntu")
118
+ allow(RSpec.configuration).to receive(:version).and_return("12.04")
119
119
  end
120
120
 
121
- it 'uses the RSpec values' do
121
+ it "uses the RSpec values" do
122
122
  options = described_class.new.options
123
- expect(options[:cookbook_path]).to eq('./path')
124
- expect(options[:environment_path]).to eq('./env-path')
125
- expect(options[:file_cache_path]).to eq('./file-cache-path')
123
+ expect(options[:cookbook_path]).to eq("./path")
124
+ expect(options[:environment_path]).to eq("./env-path")
125
+ expect(options[:file_cache_path]).to eq("./file-cache-path")
126
126
  expect(options[:log_level]).to eq(:fatal)
127
- expect(options[:path]).to eq('ohai.json')
128
- expect(options[:platform]).to eq('ubuntu')
129
- expect(options[:version]).to eq('12.04')
127
+ expect(options[:path]).to eq("ohai.json")
128
+ expect(options[:platform]).to eq("ubuntu")
129
+ expect(options[:version]).to eq("12.04")
130
130
  end
131
131
  end
132
132
  end
133
133
 
134
- describe '#node' do
135
- it 'returns the Chef::Node' do
134
+ describe "#node" do
135
+ it "returns the Chef::Node" do
136
136
  expect(subject.node).to be_a(Chef::Node)
137
137
  end
138
138
 
139
- it 'defines a #runner method that returns self' do
139
+ it "defines a #runner method that returns self" do
140
140
  expect(subject.node.methods).to include(:runner)
141
141
  expect(subject.node.runner).to be(subject)
142
142
  end
143
143
 
144
- it 'allows attributes to be set on the node' do
145
- subject.node.normal['bacon'] = 'ham'
146
- expect(subject.node.bacon).to eq('ham')
144
+ it "allows attributes to be set on the node" do
145
+ subject.node.normal["bacon"] = "ham"
146
+ expect(subject.node.bacon).to eq("ham")
147
147
  end
148
148
  end
149
149
 
150
- describe '#to_s' do
151
- it 'overrides the default string representation to something readable' do
152
- expect(subject.converge('apache2::default').to_s)
153
- .to eq('#<ChefSpec::SoloRunner run_list: [recipe[apache2::default]]>')
150
+ describe "#to_s" do
151
+ it "overrides the default string representation to something readable" do
152
+ expect(subject.converge("apache2::default").to_s)
153
+ .to eq("#<ChefSpec::SoloRunner run_list: [recipe[apache2::default]]>")
154
154
  end
155
155
 
156
- it 'is ok when a convergence has not yet taken place' do
157
- expect(subject.to_s).to eq('#<ChefSpec::SoloRunner run_list: []>')
156
+ it "is ok when a convergence has not yet taken place" do
157
+ expect(subject.to_s).to eq("#<ChefSpec::SoloRunner run_list: []>")
158
158
  end
159
159
 
160
- it 'includes the entire run_list' do
161
- expect(subject.converge('apache2::default', 'apache2::mod_ssl').to_s)
162
- .to eq('#<ChefSpec::SoloRunner run_list: [recipe[apache2::default], recipe[apache2::mod_ssl]]>')
160
+ it "includes the entire run_list" do
161
+ expect(subject.converge("apache2::default", "apache2::mod_ssl").to_s)
162
+ .to eq("#<ChefSpec::SoloRunner run_list: [recipe[apache2::default], recipe[apache2::mod_ssl]]>")
163
163
  end
164
164
 
165
- it 'has the run_list only for the last convergence' do
166
- ['mysql::client', 'mysql::server'].each { |recipe| subject.converge(recipe) }
165
+ it "has the run_list only for the last convergence" do
166
+ ["mysql::client", "mysql::server"].each { |recipe| subject.converge(recipe) }
167
167
  expect(subject.to_s)
168
- .to eq('#<ChefSpec::SoloRunner run_list: [recipe[mysql::server]]>')
168
+ .to eq("#<ChefSpec::SoloRunner run_list: [recipe[mysql::server]]>")
169
169
  end
170
170
  end
171
171
  end