chefspec 4.2.0 → 4.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -15
  3. data/CHANGELOG.md +22 -0
  4. data/README.md +50 -8
  5. data/chefspec.gemspec +1 -1
  6. data/examples/chef_gem/recipes/install.rb +8 -3
  7. data/examples/chef_gem/recipes/purge.rb +6 -3
  8. data/examples/chef_gem/recipes/reconfig.rb +6 -3
  9. data/examples/chef_gem/recipes/remove.rb +6 -3
  10. data/examples/chef_gem/recipes/upgrade.rb +6 -3
  11. data/examples/directory/recipes/create.rb +4 -0
  12. data/examples/directory/spec/create_spec.rb +4 -0
  13. data/examples/reboot/recipes/cancel.rb +3 -0
  14. data/examples/reboot/recipes/now.rb +3 -0
  15. data/examples/reboot/recipes/request.rb +3 -0
  16. data/examples/reboot/spec/cancel_spec.rb +10 -0
  17. data/examples/reboot/spec/now_spec.rb +10 -0
  18. data/examples/reboot/spec/request_spec.rb +10 -0
  19. data/examples/render_file/spec/default_spec.rb +40 -0
  20. data/examples/server/spec/search_spec.rb +4 -0
  21. data/examples/windows_service/recipes/configure_startup.rb +13 -0
  22. data/examples/windows_service/recipes/disable.rb +13 -0
  23. data/examples/windows_service/recipes/enable.rb +13 -0
  24. data/examples/windows_service/recipes/reload.rb +13 -0
  25. data/examples/windows_service/recipes/restart.rb +13 -0
  26. data/examples/windows_service/recipes/start.rb +13 -0
  27. data/examples/windows_service/recipes/stop.rb +13 -0
  28. data/examples/windows_service/spec/configure_startup_spec.rb +19 -0
  29. data/examples/windows_service/spec/disable_spec.rb +19 -0
  30. data/examples/windows_service/spec/enable_spec.rb +19 -0
  31. data/examples/windows_service/spec/reload_spec.rb +19 -0
  32. data/examples/windows_service/spec/restart_spec.rb +19 -0
  33. data/examples/windows_service/spec/start_spec.rb +19 -0
  34. data/examples/windows_service/spec/stop_spec.rb +19 -0
  35. data/features/reboot.feature +19 -0
  36. data/features/windows_service.feature +23 -0
  37. data/gemfiles/chefspec.gemfile +9 -0
  38. data/lib/chefspec.rb +1 -1
  39. data/lib/chefspec/api.rb +2 -0
  40. data/lib/chefspec/api/reboot.rb +18 -0
  41. data/lib/chefspec/api/windows_service.rb +286 -0
  42. data/lib/chefspec/coverage.rb +1 -1
  43. data/lib/chefspec/coverage/filters.rb +2 -1
  44. data/lib/chefspec/matchers/render_file_matcher.rb +19 -2
  45. data/lib/chefspec/mixins/normalize.rb +7 -1
  46. data/lib/chefspec/renderer.rb +2 -4
  47. data/lib/chefspec/rspec.rb +1 -0
  48. data/lib/chefspec/server_methods.rb +1 -0
  49. data/lib/chefspec/solo_runner.rb +5 -1
  50. data/lib/chefspec/version.rb +1 -1
  51. data/spec/unit/coverage/filters_spec.rb +60 -0
  52. data/spec/unit/renderer_spec.rb +20 -2
  53. data/spec/unit/solo_runner_spec.rb +2 -0
  54. metadata +33 -8
  55. data/gemfiles/chef-11.14.0.gemfile +0 -5
  56. data/gemfiles/chef-11.16.0.gemfile +0 -5
  57. data/gemfiles/chef-12.0.0.gemfile +0 -5
  58. data/gemfiles/chef-master.gemfile +0 -5
@@ -136,7 +136,7 @@ module ChefSpec
136
136
  puts erb.evaluate(report)
137
137
 
138
138
  # Ensure we exit correctly (#351)
139
- exit(exit_status)
139
+ Kernel.exit(exit_status) if exit_status && exit_status > 0
140
140
  end
141
141
 
142
142
  private
@@ -71,7 +71,8 @@ module ChefSpec
71
71
 
72
72
  def matches?(resource)
73
73
  return true if resource.source_line.nil?
74
- resource.source_line =~ /cookbooks\/(?!#{@metadatas.join('|')})/
74
+ normalized_source_line = resource.source_line.gsub("\\", "/")
75
+ normalized_source_line=~ /cookbooks\/(?!#{@metadatas.join('|')})/
75
76
  end
76
77
  end
77
78
  end
@@ -15,8 +15,17 @@ module ChefSpec::Matchers
15
15
  end
16
16
  end
17
17
 
18
- def with_content(expected_content)
19
- @expected_content = expected_content
18
+ def with_content(expected_content = nil, &block)
19
+ if expected_content && block
20
+ raise ArgumentError, "Cannot specify expected content and a block!"
21
+ elsif expected_content
22
+ @expected_content = expected_content
23
+ elsif block
24
+ @expected_content = block
25
+ else
26
+ raise ArgumentError, "Must specify expected content or a block!"
27
+ end
28
+
20
29
  self
21
30
  end
22
31
 
@@ -64,6 +73,8 @@ module ChefSpec::Matchers
64
73
  def expected_content_message
65
74
  if RSpec::Matchers.is_a_matcher?(@expected_content) && @expected_content.respond_to?(:description)
66
75
  @expected_content.description
76
+ elsif @expected_content.is_a?(Proc)
77
+ "(the result of a proc)"
67
78
  else
68
79
  @expected_content.to_s
69
80
  end
@@ -104,6 +115,12 @@ module ChefSpec::Matchers
104
115
  @actual_content =~ @expected_content
105
116
  elsif RSpec::Matchers.is_a_matcher?(@expected_content)
106
117
  @expected_content.matches?(@actual_content)
118
+ elsif @expected_content.is_a?(Proc)
119
+ @expected_content.call(@actual_content)
120
+ # Weird RSpecish, but that block will return false for a negated check,
121
+ # so we always return true. The block will raise an exception if the
122
+ # assertion fails.
123
+ true
107
124
  else
108
125
  @actual_content.include?(@expected_content)
109
126
  end
@@ -9,7 +9,13 @@ module ChefSpec
9
9
  # @return [Symbol]
10
10
  #
11
11
  def resource_name(thing)
12
- name = thing.respond_to?(:resource_name) ? thing.resource_name : thing
12
+ if thing.respond_to?(:declared_type)
13
+ name = thing.declared_type
14
+ elsif thing.respond_to?(:resource_name)
15
+ name = thing.resource_name
16
+ else
17
+ name = thing
18
+ end
13
19
  name.to_s.gsub('-', '_').to_sym
14
20
  end
15
21
  end
@@ -68,12 +68,10 @@ module ChefSpec
68
68
  template_context = Chef::Mixin::Template::TemplateContext.new([])
69
69
  template_context.update({
70
70
  :node => chef_run.node,
71
- :template_finder => template_finder(chef_run, template.cookbook_name),
71
+ :template_finder => template_finder(chef_run, cookbook_name),
72
72
  }.merge(template.variables))
73
73
  if template.respond_to?(:helper_modules) # Chef 11.4+
74
- template.helper_modules.each do |helper_module|
75
- template_context.extend(helper_module)
76
- end
74
+ template_context._extend_modules(template.helper_modules)
77
75
  end
78
76
  template_context.render_template(template_location)
79
77
  else
@@ -12,6 +12,7 @@ RSpec.configure do |config|
12
12
  config.add_setting :cookbook_path
13
13
  config.add_setting :role_path
14
14
  config.add_setting :environment_path
15
+ config.add_setting :file_cache_path
15
16
  config.add_setting :log_level, default: :warn
16
17
  config.add_setting :path
17
18
  config.add_setting :platform
@@ -143,6 +143,7 @@ module ChefSpec
143
143
 
144
144
  load_data(name, 'nodes', data)
145
145
  end
146
+ alias_method :update_node, :create_node
146
147
 
147
148
  #
148
149
  # Shortcut method for loading data into Chef Zero.
@@ -118,7 +118,10 @@ module ChefSpec
118
118
  yield if block_given?
119
119
 
120
120
  @converging = true
121
- @client.converge(@run_context)
121
+ converge_val = @client.converge(@run_context)
122
+ if converge_val.is_a?(Exception)
123
+ raise converge_val
124
+ end
122
125
  self
123
126
  end
124
127
 
@@ -299,6 +302,7 @@ module ChefSpec
299
302
  cookbook_path: config.cookbook_path || calling_cookbook_path(caller),
300
303
  role_path: config.role_path || default_role_path,
301
304
  environment_path: config.environment_path || default_environment_path,
305
+ file_cache_path: config.file_cache_path,
302
306
  log_level: config.log_level,
303
307
  path: config.path,
304
308
  platform: config.platform,
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '4.2.0'
2
+ VERSION = '4.3.0'
3
3
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ # Note: These specs don't use Berkshelf code directly as this project doesn't
4
+ # have a direct dependency on Berkshelf and loading it would impact the
5
+ # perfance of these specs. While not ideal, the test doubles provide enough of
6
+ # a standin for Berkshelf to exercise the `#matches?` behavior.
7
+ describe ChefSpec::Coverage::BerkshelfFilter do
8
+ let(:dependencies) do
9
+ [double('Berkshelf::Dependency', metadata?: true, name: "cookbookery")]
10
+ end
11
+ let(:berksfile) { double('Berkshelf::Berksfile', dependencies: dependencies) }
12
+ let(:resource) { Chef::Resource.new('theone') }
13
+ subject { described_class.new(berksfile) }
14
+
15
+ describe '#matches?' do
16
+ it 'returns truthy if resource source_line is nil' do
17
+ expect(subject.matches?(resource)).to be_truthy
18
+ end
19
+
20
+ context 'when resource#source_line is under target cookbook' do
21
+ it 'normal unix path returns truthy' do
22
+ resource.source_line =
23
+ '/path/to/cookbooks/nope/recipes/default.rb:22'
24
+ expect(subject.matches?(resource)).to be_truthy
25
+ end
26
+
27
+ it 'normal windows path returns truthy' do
28
+ resource.source_line =
29
+ 'C:\\path\\to\\cookbooks\\nope\\recipes\\default.rb:22'
30
+ expect(subject.matches?(resource)).to be_truthy
31
+ end
32
+
33
+ it 'mixed windows path returns truthy' do
34
+ resource.source_line =
35
+ 'C:\\path\\to\\cookbooks/nope/recipes/default.rb:22'
36
+ expect(subject.matches?(resource)).to be_truthy
37
+ end
38
+ end
39
+
40
+ context 'when resource#source_line is not under target cookbook' do
41
+ it 'normal unix path returns falsey' do
42
+ resource.source_line =
43
+ '/path/to/cookbooks/cookbookery/recipes/default.rb:22'
44
+ expect(subject.matches?(resource)).to be_falsey
45
+ end
46
+
47
+ it 'normal windows path returns falsey' do
48
+ resource.source_line =
49
+ 'C:\\path\\to\\cookbooks\\cookbookery\\recipes\\default.rb:22'
50
+ expect(subject.matches?(resource)).to be_falsey
51
+ end
52
+
53
+ it 'mixed windows path returns falsey' do
54
+ resource.source_line =
55
+ 'C:\\path\\to\\cookbooks/cookbookery/recipes/default.rb:22'
56
+ expect(subject.matches?(resource)).to be_falsey
57
+ end
58
+ end
59
+ end
60
+ end
@@ -9,8 +9,8 @@ describe ChefSpec::Renderer do
9
9
  end
10
10
  end
11
11
 
12
- let(:chef_run) { double('chef_run') }
13
- let(:resource) { double('resource') }
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
16
  describe '#content' do
@@ -48,4 +48,22 @@ describe ChefSpec::Renderer do
48
48
  end
49
49
  end
50
50
  end
51
+
52
+ describe 'content_from_template' do
53
+ it 'renders the template by extending modules for rendering paritals within the template' do
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)
57
+ allow(subject).to receive(:template_finder)
58
+
59
+ allow(resource).to receive(:helper_modules).and_return([Module.new])
60
+ allow(resource).to receive(:resource_name).and_return('template')
61
+
62
+ chef_template_context = double('context', {render_template: 'rendered template content',update: nil})
63
+ allow(Chef::Mixin::Template::TemplateContext).to receive(:new).and_return(chef_template_context)
64
+
65
+ expect(chef_template_context).to receive(:_extend_modules).with(resource.helper_modules)
66
+ expect(subject.content).to eq('rendered template content')
67
+ end
68
+ end
51
69
  end
@@ -110,6 +110,7 @@ describe ChefSpec::SoloRunner do
110
110
  before do
111
111
  allow(RSpec.configuration).to receive(:cookbook_path).and_return('./path')
112
112
  allow(RSpec.configuration).to receive(:environment_path).and_return('./env-path')
113
+ allow(RSpec.configuration).to receive(:file_cache_path).and_return('./file-cache-path')
113
114
  allow(RSpec.configuration).to receive(:log_level).and_return(:fatal)
114
115
  allow(RSpec.configuration).to receive(:path).and_return('ohai.json')
115
116
  allow(RSpec.configuration).to receive(:platform).and_return('ubuntu')
@@ -120,6 +121,7 @@ describe ChefSpec::SoloRunner do
120
121
  options = described_class.new.options
121
122
  expect(options[:cookbook_path]).to eq('./path')
122
123
  expect(options[:environment_path]).to eq('./env-path')
124
+ expect(options[:file_cache_path]).to eq('./file-cache-path')
123
125
  expect(options[:log_level]).to eq(:fatal)
124
126
  expect(options[:path]).to eq('ohai.json')
125
127
  expect(options[:platform]).to eq('ubuntu')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Crump
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-26 00:00:00.000000000 Z
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -367,6 +367,12 @@ files:
367
367
  - examples/portage_package/spec/upgrade_spec.rb
368
368
  - examples/powershell_script/recipes/run.rb
369
369
  - examples/powershell_script/spec/run_spec.rb
370
+ - examples/reboot/recipes/cancel.rb
371
+ - examples/reboot/recipes/now.rb
372
+ - examples/reboot/recipes/request.rb
373
+ - examples/reboot/spec/cancel_spec.rb
374
+ - examples/reboot/spec/now_spec.rb
375
+ - examples/reboot/spec/request_spec.rb
370
376
  - examples/registry_key/recipes/create.rb
371
377
  - examples/registry_key/recipes/create_if_missing.rb
372
378
  - examples/registry_key/recipes/delete.rb
@@ -522,6 +528,20 @@ files:
522
528
  - examples/user/spec/modify_spec.rb
523
529
  - examples/user/spec/remove_spec.rb
524
530
  - examples/user/spec/unlock_spec.rb
531
+ - examples/windows_service/recipes/configure_startup.rb
532
+ - examples/windows_service/recipes/disable.rb
533
+ - examples/windows_service/recipes/enable.rb
534
+ - examples/windows_service/recipes/reload.rb
535
+ - examples/windows_service/recipes/restart.rb
536
+ - examples/windows_service/recipes/start.rb
537
+ - examples/windows_service/recipes/stop.rb
538
+ - examples/windows_service/spec/configure_startup_spec.rb
539
+ - examples/windows_service/spec/disable_spec.rb
540
+ - examples/windows_service/spec/enable_spec.rb
541
+ - examples/windows_service/spec/reload_spec.rb
542
+ - examples/windows_service/spec/restart_spec.rb
543
+ - examples/windows_service/spec/start_spec.rb
544
+ - examples/windows_service/spec/stop_spec.rb
525
545
  - examples/yum_package/recipes/install.rb
526
546
  - examples/yum_package/recipes/purge.rb
527
547
  - examples/yum_package/recipes/remove.rb
@@ -572,6 +592,7 @@ files:
572
592
  - features/pacman_package.feature
573
593
  - features/portage_package.feature
574
594
  - features/powershell_script.feature
595
+ - features/reboot.feature
575
596
  - features/registry_key.feature
576
597
  - features/remote_directory.feature
577
598
  - features/remote_file.feature
@@ -600,11 +621,9 @@ files:
600
621
  - features/template.feature
601
622
  - features/use_inline_resources.feature
602
623
  - features/user.feature
624
+ - features/windows_service.feature
603
625
  - features/yum_package.feature
604
- - gemfiles/chef-11.14.0.gemfile
605
- - gemfiles/chef-11.16.0.gemfile
606
- - gemfiles/chef-12.0.0.gemfile
607
- - gemfiles/chef-master.gemfile
626
+ - gemfiles/chefspec.gemfile
608
627
  - lib/chefspec.rb
609
628
  - lib/chefspec/api.rb
610
629
  - lib/chefspec/api/apt_package.rb
@@ -640,6 +659,7 @@ files:
640
659
  - lib/chefspec/api/pacman_package.rb
641
660
  - lib/chefspec/api/portage_package.rb
642
661
  - lib/chefspec/api/powershell_script.rb
662
+ - lib/chefspec/api/reboot.rb
643
663
  - lib/chefspec/api/registry_key.rb
644
664
  - lib/chefspec/api/remote_directory.rb
645
665
  - lib/chefspec/api/remote_file.rb
@@ -656,6 +676,7 @@ files:
656
676
  - lib/chefspec/api/subversion.rb
657
677
  - lib/chefspec/api/template.rb
658
678
  - lib/chefspec/api/user.rb
679
+ - lib/chefspec/api/windows_service.rb
659
680
  - lib/chefspec/api/yum_package.rb
660
681
  - lib/chefspec/berkshelf.rb
661
682
  - lib/chefspec/cacher.rb
@@ -708,6 +729,7 @@ files:
708
729
  - spec/support/hash.rb
709
730
  - spec/unit/api_spec.rb
710
731
  - spec/unit/cacher_spec.rb
732
+ - spec/unit/coverage/filters_spec.rb
711
733
  - spec/unit/deprecations_spec.rb
712
734
  - spec/unit/errors_spec.rb
713
735
  - spec/unit/expect_exception_spec.rb
@@ -738,7 +760,7 @@ files:
738
760
  - templates/errors/gem_load_error.erb
739
761
  - templates/errors/no_conversion_error.erb
740
762
  - templates/errors/not_stubbed.erb
741
- homepage: http://code.sethvargo.com/chefspec
763
+ homepage: https://sethvargo.github.io/chefspec/
742
764
  licenses:
743
765
  - MIT
744
766
  metadata: {}
@@ -758,7 +780,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
758
780
  version: '0'
759
781
  requirements: []
760
782
  rubyforge_project:
761
- rubygems_version: 2.2.2
783
+ rubygems_version: 2.2.3
762
784
  signing_key:
763
785
  specification_version: 4
764
786
  summary: Write RSpec examples and generate coverage reports for Chef recipes!
@@ -805,6 +827,7 @@ test_files:
805
827
  - features/pacman_package.feature
806
828
  - features/portage_package.feature
807
829
  - features/powershell_script.feature
830
+ - features/reboot.feature
808
831
  - features/registry_key.feature
809
832
  - features/remote_directory.feature
810
833
  - features/remote_file.feature
@@ -833,11 +856,13 @@ test_files:
833
856
  - features/template.feature
834
857
  - features/use_inline_resources.feature
835
858
  - features/user.feature
859
+ - features/windows_service.feature
836
860
  - features/yum_package.feature
837
861
  - spec/spec_helper.rb
838
862
  - spec/support/hash.rb
839
863
  - spec/unit/api_spec.rb
840
864
  - spec/unit/cacher_spec.rb
865
+ - spec/unit/coverage/filters_spec.rb
841
866
  - spec/unit/deprecations_spec.rb
842
867
  - spec/unit/errors_spec.rb
843
868
  - spec/unit/expect_exception_spec.rb
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'chef', '~> 11.14.0'
4
-
5
- gemspec path: '..'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'chef', '~> 11.16.0'
4
-
5
- gemspec path: '..'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'chef', '~> 12.0.0'
4
-
5
- gemspec path: '..'
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'chef', github: 'opscode/chef'
4
-
5
- gemspec :path => '..'