chefspec 4.7.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -21
  3. data/CHANGELOG.md +18 -0
  4. data/Gemfile +1 -0
  5. data/README.md +37 -20
  6. data/chefspec.gemspec +4 -4
  7. data/examples/apt_repository/recipes/add.rb +8 -0
  8. data/examples/apt_repository/recipes/remove.rb +4 -0
  9. data/examples/apt_repository/spec/add_spec.rb +14 -0
  10. data/examples/apt_repository/spec/remove_spec.rb +9 -0
  11. data/examples/apt_update/recipes/periodic.rb +5 -0
  12. data/examples/apt_update/recipes/update.rb +3 -0
  13. data/examples/apt_update/spec/periodic_spec.rb +14 -0
  14. data/examples/apt_update/spec/update_spec.rb +9 -0
  15. data/examples/attributes/spec/default_spec.rb +1 -1
  16. data/examples/notifications/recipes/before.rb +7 -0
  17. data/examples/notifications/spec/before_spec.rb +16 -0
  18. data/examples/server/spec/node_spec.rb +3 -3
  19. data/examples/server/spec/search_spec.rb +4 -4
  20. data/examples/stub_node/spec/default_spec.rb +2 -2
  21. data/examples/subscribes/recipes/before.rb +5 -0
  22. data/examples/subscribes/spec/before_spec.rb +16 -0
  23. data/examples/user/spec/create_spec.rb +1 -1
  24. data/examples/user/spec/lock_spec.rb +1 -1
  25. data/examples/user/spec/manage_spec.rb +1 -1
  26. data/examples/user/spec/modify_spec.rb +1 -1
  27. data/examples/user/spec/remove_spec.rb +1 -1
  28. data/examples/user/spec/unlock_spec.rb +1 -1
  29. data/features/chocolatey_package.feature +0 -10
  30. data/features/dsc_resource.feature +0 -9
  31. data/features/notifications.feature +8 -0
  32. data/features/reboot.feature +0 -7
  33. data/features/step_into.feature +0 -7
  34. data/features/subscribes.feature +8 -0
  35. data/features/windows_package.feature +0 -9
  36. data/features/windows_service.feature +0 -7
  37. data/gemfiles/chefspec.gemfile +6 -0
  38. data/lib/chefspec/api/apt_repository.rb +56 -0
  39. data/lib/chefspec/api/apt_update.rb +53 -0
  40. data/lib/chefspec/cacher.rb +3 -2
  41. data/lib/chefspec/coverage.rb +38 -5
  42. data/lib/chefspec/errors.rb +3 -0
  43. data/lib/chefspec/extensions/chef/data_query.rb +2 -2
  44. data/lib/chefspec/matchers/notifications_matcher.rb +23 -2
  45. data/lib/chefspec/matchers/subscribes_matcher.rb +9 -0
  46. data/lib/chefspec/version.rb +1 -1
  47. data/spec/spec_helper.rb +5 -0
  48. data/spec/unit/cacher_spec.rb +17 -1
  49. data/spec/unit/matchers/notifications_matcher_spec.rb +1 -0
  50. data/spec/unit/matchers/subscribes_matcher_spec.rb +1 -0
  51. data/spec/unit/solo_runner_spec.rb +1 -1
  52. data/templates/coverage/json.erb +8 -0
  53. data/templates/coverage/table.erb +14 -0
  54. data/templates/errors/erb_template_parse_error.erb +5 -0
  55. data/templates/errors/template_not_found.erb +9 -0
  56. metadata +26 -11
  57. data/spec/unit/extensions/lwrp_base_spec.rb +0 -96
@@ -22,6 +22,8 @@ module ChefSpec::Matchers
22
22
  immediate_notifications.any?(&block)
23
23
  elsif @delayed
24
24
  delayed_notifications.any?(&block)
25
+ elsif @before
26
+ before_notifications.any?(&block)
25
27
  else
26
28
  all_notifications.any?(&block)
27
29
  end
@@ -43,11 +45,17 @@ module ChefSpec::Matchers
43
45
  self
44
46
  end
45
47
 
48
+ def before
49
+ @before = true
50
+ self
51
+ end
52
+
46
53
  def description
47
54
  message = %Q{notify "#{@expected_resource_type}[#{@expected_resource_name}]"}
48
55
  message << " with action :#{@action}" if @action
49
56
  message << " immediately" if @immediately
50
57
  message << " delayed" if @delayed
58
+ message << " before" if @before
51
59
  message
52
60
  end
53
61
 
@@ -57,6 +65,7 @@ module ChefSpec::Matchers
57
65
  message << " with action :#{@action}" if @action
58
66
  message << " immediately" if @immediately
59
67
  message << " delayed" if @delayed
68
+ message << " before" if @before
60
69
  message << ", but did not."
61
70
  message << "\n\n"
62
71
  message << "Other notifications were:\n\n#{format_notifications}"
@@ -67,6 +76,7 @@ module ChefSpec::Matchers
67
76
  message << " with action :#{@action}" if @action
68
77
  message << " immediately" if @immediately
69
78
  message << " delayed" if @delayed
79
+ message << " before" if @before
70
80
  message << ", but the _something_ you gave me was nil! If you are running a test like:"
71
81
  message << "\n\n"
72
82
  message << " expect(_something_).to notify('...')"
@@ -88,7 +98,7 @@ module ChefSpec::Matchers
88
98
  private
89
99
 
90
100
  def all_notifications
91
- immediate_notifications + delayed_notifications
101
+ immediate_notifications + delayed_notifications + before_notifications
92
102
  end
93
103
 
94
104
  def immediate_notifications
@@ -99,6 +109,10 @@ module ChefSpec::Matchers
99
109
  @resource.delayed_notifications
100
110
  end
101
111
 
112
+ def before_notifications
113
+ @resource.before_notifications
114
+ end
115
+
102
116
  def matches_action?(notification)
103
117
  return true if @action.nil?
104
118
  @action == notification.action.to_sym
@@ -107,7 +121,14 @@ module ChefSpec::Matchers
107
121
  def format_notification(notification)
108
122
  notifying_resource = notification.notifying_resource
109
123
  resource = notification.resource
110
- type = notification.notifying_resource.immediate_notifications.include?(notification) ? :immediately : :delayed
124
+
125
+ if notifying_resource.immediate_notifications.include?(notification)
126
+ type = :immediately
127
+ elsif notifying_resource.before_notifications.include?(notification)
128
+ type = :before
129
+ else
130
+ type = :delayed
131
+ end
111
132
 
112
133
  %Q{ "#{notifying_resource.to_s}" notifies "#{resource_name(resource)}[#{resource.name}]" to :#{notification.action}, :#{type}}
113
134
  end
@@ -23,6 +23,10 @@ module ChefSpec::Matchers
23
23
  @instance.delayed
24
24
  end
25
25
 
26
+ if @before
27
+ @instance.before
28
+ end
29
+
26
30
  if resource
27
31
  runner = resource.run_context.node.runner
28
32
  expected = runner.find_resource(@expected_resource_type, @expected_resource_name)
@@ -48,6 +52,11 @@ module ChefSpec::Matchers
48
52
  self
49
53
  end
50
54
 
55
+ def before
56
+ @before = true
57
+ self
58
+ end
59
+
51
60
  def description
52
61
  @instance.description
53
62
  end
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '4.7.0'
2
+ VERSION = '5.0.0'
3
3
  end
@@ -1,6 +1,11 @@
1
1
  require 'chefspec'
2
2
  require 'support/hash'
3
3
 
4
+
5
+ ChefSpec::Coverage.start! do
6
+ set_template 'table.erb'
7
+ end
8
+
4
9
  RSpec.configure do |config|
5
10
  config.expect_with(:rspec) { |c| c.syntax = :expect }
6
11
  config.filter_run(focus: true)
@@ -13,8 +13,9 @@ describe ChefSpec::Cacher do
13
13
  end
14
14
 
15
15
  let(:cache) { described_class.class_variable_get(:@@cache) }
16
+ let(:preserve_cache) { false }
16
17
 
17
- before(:each) { described_class.class_variable_set(:@@cache, {}) }
18
+ before(:each) { described_class.class_variable_set(:@@cache, {}) unless preserve_cache }
18
19
 
19
20
  describe 'cached' do
20
21
  it 'lazily defines the results for the cache' do
@@ -41,6 +42,21 @@ describe ChefSpec::Cacher do
41
42
  end
42
43
  end
43
44
  end
45
+
46
+ context 'when example groups are defined by looping' do
47
+ let(:preserve_cache) { true }
48
+
49
+ ['first', 'second', 'third'].each do |iteration|
50
+ context "on the #{iteration} iteration" do
51
+ context 'in caching context' do
52
+ cached(:cached_iteration) { iteration }
53
+ it 'caches the iteration for this context' do
54
+ expect(cached_iteration).to eq iteration
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
44
60
  end
45
61
 
46
62
  describe 'cached!' do
@@ -10,6 +10,7 @@ describe ChefSpec::Matchers::NotificationsMatcher do
10
10
  performed_action?: true,
11
11
  immediate_notifications: [],
12
12
  delayed_notifications: [],
13
+ before_notifications: []
13
14
  )
14
15
  end
15
16
 
@@ -30,6 +30,7 @@ describe ChefSpec::Matchers::SubscribesMatcher do
30
30
  to_s: 'execute[install]',
31
31
  immediate_notifications: [],
32
32
  delayed_notifications: [],
33
+ before_notifications: []
33
34
  )
34
35
  end
35
36
 
@@ -141,7 +141,7 @@ describe ChefSpec::SoloRunner do
141
141
  end
142
142
 
143
143
  it 'allows attributes to be set on the node' do
144
- subject.node.set['bacon'] = 'ham'
144
+ subject.node.normal['bacon'] = 'ham'
145
145
  expect(subject.node.bacon).to eq('ham')
146
146
  end
147
147
  end
@@ -0,0 +1,8 @@
1
+ { "resources":[
2
+ <%= @all_resources.map { |resource| resource.to_json }.join(",\n") %>
3
+ ],
4
+ "resource_count": <%= @total %>,
5
+ "resources_touched": <%= @touched %>,
6
+ "resource_coverage": <%= @coverage %>
7
+
8
+ }
@@ -0,0 +1,14 @@
1
+ <%='Touched'.to_s.ljust(8) %> <%='Resource'.to_s.ljust(48) %> File:Line
2
+ <% @all_resources.each do |resource| %>
3
+ <%=resource.touched?.to_s.ljust(8) %> <%= resource.to_s.ljust(48) %> <%= resource.source_file %>:<%= resource.source_line %>
4
+ <% end %>
5
+
6
+ <% if @total == 0 %>
7
+ No Chef resources found, skipping coverage calculation...
8
+ <% else %>
9
+ ChefSpec Coverage report generated...
10
+
11
+ Total Resources: <%= @total %>
12
+ Touched Resources: <%= @touched %>
13
+ Touch Coverage: <%= @coverage %>%
14
+ <% end %>
@@ -0,0 +1,5 @@
1
+ An Error occured during parsing the Erb Given.
2
+
3
+ Here is the original error:
4
+
5
+ <%= @original_error %>
@@ -0,0 +1,9 @@
1
+ The template specified cannot be found.
2
+
3
+ The template for a Coverage.report!
4
+ cannot be found given the following path:
5
+
6
+ <%= @path %>
7
+
8
+ please check your set_template parameters.
9
+
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.7.0
4
+ version: 5.0.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: 2016-05-14 00:00:00.000000000 Z
12
+ date: 2016-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '11.14'
20
+ version: '12.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '11.14'
27
+ version: '12.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: fauxhai
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.2'
34
+ version: '3.6'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '3.2'
41
+ version: '3.6'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +139,14 @@ files:
139
139
  - examples/apt_package/spec/reconfig_spec.rb
140
140
  - examples/apt_package/spec/remove_spec.rb
141
141
  - examples/apt_package/spec/upgrade_spec.rb
142
+ - examples/apt_repository/recipes/add.rb
143
+ - examples/apt_repository/recipes/remove.rb
144
+ - examples/apt_repository/spec/add_spec.rb
145
+ - examples/apt_repository/spec/remove_spec.rb
146
+ - examples/apt_update/recipes/periodic.rb
147
+ - examples/apt_update/recipes/update.rb
148
+ - examples/apt_update/spec/periodic_spec.rb
149
+ - examples/apt_update/spec/update_spec.rb
142
150
  - examples/attributes/attributes/default.rb
143
151
  - examples/attributes/recipes/default.rb
144
152
  - examples/attributes/spec/default_spec.rb
@@ -337,10 +345,12 @@ files:
337
345
  - examples/multiple_actions/spec/sequential_spec.rb
338
346
  - examples/multiple_run_action/recipes/default.rb
339
347
  - examples/multiple_run_action/spec/default_spec.rb
348
+ - examples/notifications/recipes/before.rb
340
349
  - examples/notifications/recipes/chained.rb
341
350
  - examples/notifications/recipes/default.rb
342
351
  - examples/notifications/recipes/delayed.rb
343
352
  - examples/notifications/recipes/immediately.rb
353
+ - examples/notifications/spec/before_spec.rb
344
354
  - examples/notifications/spec/chained_spec.rb
345
355
  - examples/notifications/spec/default_spec.rb
346
356
  - examples/notifications/spec/delayed_spec.rb
@@ -497,10 +507,12 @@ files:
497
507
  - examples/stub_node/spec/default_spec.rb
498
508
  - examples/stub_search/recipes/default.rb
499
509
  - examples/stub_search/spec/default_spec.rb
510
+ - examples/subscribes/recipes/before.rb
500
511
  - examples/subscribes/recipes/chained.rb
501
512
  - examples/subscribes/recipes/default.rb
502
513
  - examples/subscribes/recipes/delayed.rb
503
514
  - examples/subscribes/recipes/immediately.rb
515
+ - examples/subscribes/spec/before_spec.rb
504
516
  - examples/subscribes/spec/chained_spec.rb
505
517
  - examples/subscribes/spec/default_spec.rb
506
518
  - examples/subscribes/spec/delayed_spec.rb
@@ -644,6 +656,8 @@ files:
644
656
  - lib/chefspec.rb
645
657
  - lib/chefspec/api.rb
646
658
  - lib/chefspec/api/apt_package.rb
659
+ - lib/chefspec/api/apt_repository.rb
660
+ - lib/chefspec/api/apt_update.rb
647
661
  - lib/chefspec/api/batch.rb
648
662
  - lib/chefspec/api/chef_gem.rb
649
663
  - lib/chefspec/api/chocolatey_package.rb
@@ -755,7 +769,6 @@ files:
755
769
  - spec/unit/deprecations_spec.rb
756
770
  - spec/unit/errors_spec.rb
757
771
  - spec/unit/expect_exception_spec.rb
758
- - spec/unit/extensions/lwrp_base_spec.rb
759
772
  - spec/unit/macros_spec.rb
760
773
  - spec/unit/matchers/do_nothing_matcher.rb
761
774
  - spec/unit/matchers/include_recipe_matcher_spec.rb
@@ -779,12 +792,16 @@ files:
779
792
  - spec/unit/stubs/search_stub_spec.rb
780
793
  - spec/unit/stubs/stub_spec.rb
781
794
  - templates/coverage/human.erb
795
+ - templates/coverage/json.erb
796
+ - templates/coverage/table.erb
782
797
  - templates/errors/cookbook_path_not_found.erb
798
+ - templates/errors/erb_template_parse_error.erb
783
799
  - templates/errors/gem_load_error.erb
784
800
  - templates/errors/invalid_berkshelf_options.erb
785
801
  - templates/errors/may_need_to_specify_platform.erb
786
802
  - templates/errors/no_conversion_error.erb
787
803
  - templates/errors/not_stubbed.erb
804
+ - templates/errors/template_not_found.erb
788
805
  homepage: https://sethvargo.github.io/chefspec/
789
806
  licenses:
790
807
  - MIT
@@ -797,7 +814,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
797
814
  requirements:
798
815
  - - ">="
799
816
  - !ruby/object:Gem::Version
800
- version: '1.9'
817
+ version: '2.1'
801
818
  required_rubygems_version: !ruby/object:Gem::Requirement
802
819
  requirements:
803
820
  - - ">="
@@ -805,7 +822,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
805
822
  version: '0'
806
823
  requirements: []
807
824
  rubyforge_project:
808
- rubygems_version: 2.2.3
825
+ rubygems_version: 2.6.6
809
826
  signing_key:
810
827
  specification_version: 4
811
828
  summary: Write RSpec examples and generate coverage reports for Chef recipes!
@@ -894,7 +911,6 @@ test_files:
894
911
  - spec/unit/deprecations_spec.rb
895
912
  - spec/unit/errors_spec.rb
896
913
  - spec/unit/expect_exception_spec.rb
897
- - spec/unit/extensions/lwrp_base_spec.rb
898
914
  - spec/unit/macros_spec.rb
899
915
  - spec/unit/matchers/do_nothing_matcher.rb
900
916
  - spec/unit/matchers/include_recipe_matcher_spec.rb
@@ -917,4 +933,3 @@ test_files:
917
933
  - spec/unit/stubs/search_registry_spec.rb
918
934
  - spec/unit/stubs/search_stub_spec.rb
919
935
  - spec/unit/stubs/stub_spec.rb
920
- has_rdoc:
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Chef 12 fixed resource inheritance issues
4
- if Chef::VERSION.to_f < 12.0
5
- module ChefSpec
6
- module Extensions
7
- describe :LWRPBase do
8
- describe '#remove_existing_lwrp' do
9
- before do
10
- Chef::Provider::MysqlDatabase = nil
11
- Chef::Resource::MysqlDatabase = Class.new(Chef::Resource)
12
- end
13
-
14
- after do
15
- [Chef::Provider, Chef::Resource].each do |mod|
16
- next unless mod.const_defined?(:MysqlDatabase, false)
17
- mod.send(:remove_const, :MysqlDatabase)
18
- end
19
- end
20
-
21
- context Chef::Provider do
22
- before do
23
- Chef::Provider::LWRPBase.remove_existing_lwrp('MysqlDatabase')
24
- end
25
-
26
- it 'removes the provider if it already exists' do
27
- expect(Chef::Provider.constants).to_not include(:MysqlDatabase)
28
- end
29
-
30
- it 'does not remove resource' do
31
- expect(Chef::Resource.constants).to include(:MysqlDatabase)
32
- end
33
-
34
- it 'does not throw an error if the resource does not already exist' do
35
- expect {
36
- Chef::Provider::LWRPBase.remove_existing_lwrp 'Human'
37
- }.to_not raise_error
38
- end
39
- end
40
-
41
- context Chef::Resource do
42
- let!(:resource_class) { Chef::Resource::MysqlDatabase }
43
-
44
- before do
45
- Chef::Resource::LWRPBase.remove_existing_lwrp('MysqlDatabase')
46
- end
47
-
48
- it 'removes the resource if it already exists' do
49
- expect(Chef::Resource.constants).to_not include(:MysqlDatabase)
50
- end
51
-
52
- if Chef::Resource.respond_to?(:resource_classes)
53
- it 'removes the resource from Chef::Resource.resource_classes' do
54
- expect(Chef::Resource.resource_classes).to_not include(resource_class)
55
- end
56
- end
57
-
58
- it 'does not remove the provider' do
59
- Chef::Resource::LWRPBase.remove_existing_lwrp('MysqlDatabase')
60
- expect(Chef::Provider.constants).to include(:MysqlDatabase)
61
- end
62
-
63
- it 'does not throw an error if the resource does not already exist' do
64
- expect {
65
- Chef::Resource::LWRPBase.remove_existing_lwrp 'Human'
66
- }.to_not raise_error
67
- end
68
- end
69
- end
70
- end
71
-
72
- describe '#build_from_file' do
73
- let(:args){ %w{mycookbook thisfile context} }
74
-
75
- shared_context "wrapping" do
76
- it 'wraps the existing chef build_from_file method' do
77
- klass = mod::LWRPBase
78
- allow(klass).to receive(:build_from_file_without_removal)
79
- expect(klass).to receive(:build_from_file_without_removal).with(*args)
80
- klass.build_from_file(*args)
81
- end
82
- end
83
-
84
- context Chef::Provider do
85
- let(:mod){ Chef::Provider }
86
- include_context "wrapping"
87
- end
88
-
89
- context Chef::Resource do
90
- let(:mod){ Chef::Resource }
91
- include_context "wrapping"
92
- end
93
- end
94
- end
95
- end
96
- end