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
@@ -34,6 +34,9 @@ describe 'server::search' do
34
34
 
35
35
  let(:chef_run) do
36
36
  ChefSpec::ServerRunner.new do |node, server|
37
+ node.set['bar'] = true
38
+ server.update_node(node)
39
+
37
40
  server.create_node(node_1)
38
41
  server.create_node(node_2)
39
42
  server.create_node(node_3)
@@ -44,6 +47,7 @@ describe 'server::search' do
44
47
  it 'finds all nodes with the bar attribute' do
45
48
  expect(chef_run).to write_log('nodes with an attribute')
46
49
  .with_message(<<-EOH.gsub(/^ {8}/, '').strip)
50
+ chefspec, FQDN: chefspec.local, hostname: chefspec
47
51
  node_1, FQDN: node_1.example.com, hostname: node_1
48
52
  node_2, FQDN: node_2.example.com, hostname: node_2
49
53
  node_3, FQDN: node_3.example.com, hostname: node_3
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :configure_startup
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :configure_startup
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :configure_startup
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :disable
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :disable
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :disable
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :enable
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :enable
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :enable
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :reload
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :reload
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :reload
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :restart
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :restart
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :restart
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :start
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :start
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :start
13
+ end
@@ -0,0 +1,13 @@
1
+ windows_service 'explicit_action' do
2
+ action :stop
3
+ end
4
+
5
+ windows_service 'with_attributes' do
6
+ pattern 'pattern'
7
+ action :stop
8
+ end
9
+
10
+ windows_service 'specifying the identity attribute' do
11
+ service_name 'identity_attribute'
12
+ action :stop
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::configure_startup' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'configures startup for a windows_service with an explicit action' do
7
+ expect(chef_run).to configure_startup_windows_service('explicit_action')
8
+ expect(chef_run).to_not configure_startup_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'configures startup for a windows_service with attributes' do
12
+ expect(chef_run).to configure_startup_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not configure_startup_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'configures startup for a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to configure_startup_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::disable' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'disables a windows_service with an explicit action' do
7
+ expect(chef_run).to disable_windows_service('explicit_action')
8
+ expect(chef_run).to_not disable_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'disables a windows_service with attributes' do
12
+ expect(chef_run).to disable_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not disable_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'disables a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to disable_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::enable' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'enables a windows_service with an explicit action' do
7
+ expect(chef_run).to enable_windows_service('explicit_action')
8
+ expect(chef_run).to_not enable_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'enables a windows_service with attributes' do
12
+ expect(chef_run).to enable_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not enable_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'enables a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to enable_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::reload' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'reloads a windows_service with an explicit action' do
7
+ expect(chef_run).to reload_windows_service('explicit_action')
8
+ expect(chef_run).to_not reload_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'reloads a windows_service with attributes' do
12
+ expect(chef_run).to reload_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not reload_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'reloads a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to reload_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::restart' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'restarts a windows_service with an explicit action' do
7
+ expect(chef_run).to restart_windows_service('explicit_action')
8
+ expect(chef_run).to_not restart_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'restarts a windows_service with attributes' do
12
+ expect(chef_run).to restart_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not restart_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'restarts a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to restart_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::start' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'starts a windows_service with an explicit action' do
7
+ expect(chef_run).to start_windows_service('explicit_action')
8
+ expect(chef_run).to_not start_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'starts a windows_service with attributes' do
12
+ expect(chef_run).to start_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not start_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'starts a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to start_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'chefspec'
2
+
3
+ describe 'windows_service::stop' do
4
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
5
+
6
+ it 'stops a windows_service with an explicit action' do
7
+ expect(chef_run).to stop_windows_service('explicit_action')
8
+ expect(chef_run).to_not stop_windows_service('not_explicit_action')
9
+ end
10
+
11
+ it 'stops a windows_service with attributes' do
12
+ expect(chef_run).to stop_windows_service('with_attributes').with(pattern: 'pattern')
13
+ expect(chef_run).to_not stop_windows_service('with_attributes').with(pattern: 'bacon')
14
+ end
15
+
16
+ it 'stops a windows_service when specifying the identity attribute' do
17
+ expect(chef_run).to stop_windows_service('identity_attribute')
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ @not_chef_11_14_2
2
+ @not_chef_11_14_6
3
+ @not_chef_11_16_0
4
+ @not_chef_11_16_2
5
+ @not_chef_11_16_4
6
+ @not_chef_11_18_0
7
+ @not_chef_11_18_6
8
+ Feature: The reboot matcher
9
+ Background:
10
+ * I am using the "reboot" cookbook
11
+
12
+ Scenario Outline: Running specs
13
+ * I successfully run `rspec spec/<Matcher>_spec.rb`
14
+ * the output should contain "0 failures"
15
+ Examples:
16
+ | Matcher |
17
+ | request |
18
+ | now |
19
+ | cancel |
@@ -0,0 +1,23 @@
1
+ @not_chef_11_14_2
2
+ @not_chef_11_14_6
3
+ @not_chef_11_16_0
4
+ @not_chef_11_16_2
5
+ @not_chef_11_16_4
6
+ @not_chef_11_18_0
7
+ @not_chef_11_18_6
8
+ Feature: The windows_service matcher
9
+ Background:
10
+ * I am using the "windows_service" cookbook
11
+
12
+ Scenario Outline: Running specs
13
+ * I successfully run `rspec spec/<Matcher>_spec.rb`
14
+ * the output should contain "0 failures"
15
+ Examples:
16
+ | Matcher |
17
+ | configure_startup |
18
+ | disable |
19
+ | enable |
20
+ | reload |
21
+ | restart |
22
+ | start |
23
+ | stop |
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ if ENV['CHEF_VERSION'] == 'master'
4
+ gem 'chef', github: 'chef/chef'
5
+ else
6
+ gem 'chef', ENV['CHEF_VERSION']
7
+ end
8
+
9
+ gemspec path: '..'
data/lib/chefspec.rb CHANGED
@@ -42,13 +42,13 @@ module ChefSpec
42
42
  module_function :matchers
43
43
  end
44
44
 
45
+ require_relative 'chefspec/extensions/chef/securable'
45
46
  require_relative 'chefspec/extensions/chef/client'
46
47
  require_relative 'chefspec/extensions/chef/conditional'
47
48
  require_relative 'chefspec/extensions/chef/cookbook_uploader'
48
49
  require_relative 'chefspec/extensions/chef/data_query'
49
50
  require_relative 'chefspec/extensions/chef/lwrp_base'
50
51
  require_relative 'chefspec/extensions/chef/resource'
51
- require_relative 'chefspec/extensions/chef/securable'
52
52
  require_relative 'chefspec/extensions/chef/resource/freebsd_package'
53
53
 
54
54
  require_relative 'chefspec/mixins/normalize'
data/lib/chefspec/api.rb CHANGED
@@ -57,6 +57,7 @@ require_relative 'api/package'
57
57
  require_relative 'api/pacman_package'
58
58
  require_relative 'api/portage_package'
59
59
  require_relative 'api/powershell_script'
60
+ require_relative 'api/reboot'
60
61
  require_relative 'api/registry_key'
61
62
  require_relative 'api/remote_directory'
62
63
  require_relative 'api/remote_file'
@@ -73,4 +74,5 @@ require_relative 'api/subscriptions'
73
74
  require_relative 'api/subversion'
74
75
  require_relative 'api/template'
75
76
  require_relative 'api/user'
77
+ require_relative 'api/windows_service'
76
78
  require_relative 'api/yum_package'
@@ -0,0 +1,18 @@
1
+ module ChefSpec::API
2
+ # @since 0.5.0
3
+ module RebootMatchers
4
+ ChefSpec.define_matcher :reboot
5
+
6
+ def now_reboot(resource_name)
7
+ ChefSpec::Matchers::ResourceMatcher.new(:reboot, :reboot_now, resource_name)
8
+ end
9
+
10
+ def request_reboot(resource_name)
11
+ ChefSpec::Matchers::ResourceMatcher.new(:reboot, :request_reboot, resource_name)
12
+ end
13
+
14
+ def cancel_reboot(resource_name)
15
+ ChefSpec::Matchers::ResourceMatcher.new(:reboot, :cancel, resource_name)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,286 @@
1
+ module ChefSpec::API
2
+ # @since 0.5.0
3
+ module WindowsServiceMatchers
4
+ ChefSpec.define_matcher :windows_service
5
+
6
+ #
7
+ # Assert that a +windows_service+ resource exists in the Chef run with the
8
+ # action +:configure_startup+. Given a Chef Recipe that configures startup for "BITS" as a
9
+ # +windows_service+:
10
+ #
11
+ # windows_service 'BITS' do
12
+ # action :configure_startup
13
+ # end
14
+ #
15
+ # To test the content rendered by a +windows_service+, see
16
+ # {ChefSpec::API::RenderFileMatchers}.
17
+ #
18
+ # The Examples section demonstrates the different ways to test a
19
+ # +windows_service+ resource with ChefSpec.
20
+ #
21
+ # @example Assert that a +windows_service+ had its startup configured
22
+ # expect(chef_run).to disable_windows_service('BITS')
23
+ #
24
+ # @example Assert that a +windows_service+ had its startup configured with predicate matchers
25
+ # expect(chef_run).to disable_windows_service('BITS').with_pattern('BI*')
26
+ #
27
+ # @example Assert that a +windows_service+ had its startup configured with attributes
28
+ # expect(chef_run).to disable_windows_service('BITS').with(pattern: 'BI*')
29
+ #
30
+ # @example Assert that a +windows_service+ had its startup configured using a regex
31
+ # expect(chef_run).to disable_windows_service('BITS').with(pattern: /(.+)/)
32
+ #
33
+ # @example Assert that a +windows_service+ did _not_ have its startup configured
34
+ # expect(chef_run).to_not disable_windows_service('BITS')
35
+ #
36
+ #
37
+ # @param [String, Regex] resource_name
38
+ # the name of the resource to match
39
+ #
40
+ # @return [ChefSpec::Matchers::ResourceMatcher]
41
+ #
42
+ def configure_startup_windows_service(resource_name)
43
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :configure_startup, resource_name)
44
+ end
45
+
46
+ #
47
+ # Assert that a +windows_service+ resource exists in the Chef run with the
48
+ # action +:disable+. Given a Chef Recipe that disables "BITS" as a
49
+ # +windows_service+:
50
+ #
51
+ # windows_service 'BITS' do
52
+ # action :disable
53
+ # end
54
+ #
55
+ # To test the content rendered by a +windows_service+, see
56
+ # {ChefSpec::API::RenderFileMatchers}.
57
+ #
58
+ # The Examples section demonstrates the different ways to test a
59
+ # +windows_service+ resource with ChefSpec.
60
+ #
61
+ # @example Assert that a +windows_service+ was disabled
62
+ # expect(chef_run).to disable_windows_service('BITS')
63
+ #
64
+ # @example Assert that a +windows_service+ was disabled with predicate matchers
65
+ # expect(chef_run).to disable_windows_service('BITS').with_pattern('BI*')
66
+ #
67
+ # @example Assert that a +windows_service+ was disabled with attributes
68
+ # expect(chef_run).to disable_windows_service('BITS').with(pattern: 'BI*')
69
+ #
70
+ # @example Assert that a +windows_service+ was disabled using a regex
71
+ # expect(chef_run).to disable_windows_service('BITS').with(pattern: /(.+)/)
72
+ #
73
+ # @example Assert that a +windows_service+ was _not_ disabled
74
+ # expect(chef_run).to_not disable_windows_service('BITS')
75
+ #
76
+ #
77
+ # @param [String, Regex] resource_name
78
+ # the name of the resource to match
79
+ #
80
+ # @return [ChefSpec::Matchers::ResourceMatcher]
81
+ #
82
+ def disable_windows_service(resource_name)
83
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :disable, resource_name)
84
+ end
85
+
86
+ #
87
+ # Assert that a +windows_service+ resource exists in the Chef run with the
88
+ # action +:enable+. Given a Chef Recipe that enables "BITS" as a
89
+ # +windows_service+:
90
+ #
91
+ # windows_service 'BITS' do
92
+ # action :enable
93
+ # end
94
+ #
95
+ # To test the content rendered by a +windows_service+, see
96
+ # {ChefSpec::API::RenderFileMatchers}.
97
+ #
98
+ # The Examples section demonstrates the different ways to test a
99
+ # +windows_service+ resource with ChefSpec.
100
+ #
101
+ # @example Assert that a +windows_service+ was enabled
102
+ # expect(chef_run).to enable_windows_service('BITS')
103
+ #
104
+ # @example Assert that a +windows_service+ was enabled with predicate matchers
105
+ # expect(chef_run).to enable_windows_service('BITS').with_pattern('BI*')
106
+ #
107
+ # @example Assert that a +windows_service+ was enabled with attributes
108
+ # expect(chef_run).to enable_windows_service('BITS').with(pattern: 'BI*')
109
+ #
110
+ # @example Assert that a +windows_service+ was enabled using a regex
111
+ # expect(chef_run).to enable_windows_service('BITS').with(pattern: /(.+)/)
112
+ #
113
+ # @example Assert that a +windows_service+ was _not_ enabled
114
+ # expect(chef_run).to_not enable_windows_service('BITS')
115
+ #
116
+ #
117
+ # @param [String, Regex] resource_name
118
+ # the name of the resource to match
119
+ #
120
+ # @return [ChefSpec::Matchers::ResourceMatcher]
121
+ #
122
+ def enable_windows_service(resource_name)
123
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :enable, resource_name)
124
+ end
125
+
126
+ #
127
+ # Assert that a +windows_service+ resource exists in the Chef run with the
128
+ # action +:reload+. Given a Chef Recipe that reloads "BITS" as a
129
+ # +windows_service+:
130
+ #
131
+ # windows_service 'BITS' do
132
+ # action :reload
133
+ # end
134
+ #
135
+ # To test the content rendered by a +windows_service+, see
136
+ # {ChefSpec::API::RenderFileMatchers}.
137
+ #
138
+ # The Examples section demonstrates the different ways to test a
139
+ # +windows_service+ resource with ChefSpec.
140
+ #
141
+ # @example Assert that a +windows_service+ was reload
142
+ # expect(chef_run).to reload_windows_service('BITS')
143
+ #
144
+ # @example Assert that a +windows_service+ was reload with predicate matchers
145
+ # expect(chef_run).to reload_windows_service('BITS').with_pattern('BI*')
146
+ #
147
+ # @example Assert that a +windows_service+ was reload with attributes
148
+ # expect(chef_run).to reload_windows_service('BITS').with(pattern: 'BI*')
149
+ #
150
+ # @example Assert that a +windows_service+ was reload using a regex
151
+ # expect(chef_run).to reload_windows_service('BITS').with(pattern: /(.+)/)
152
+ #
153
+ # @example Assert that a +windows_service+ was _not_ reload
154
+ # expect(chef_run).to_not reload_windows_service('BITS')
155
+ #
156
+ #
157
+ # @param [String, Regex] resource_name
158
+ # the name of the resource to match
159
+ #
160
+ # @return [ChefSpec::Matchers::ResourceMatcher]
161
+ #
162
+ def reload_windows_service(resource_name)
163
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :reload, resource_name)
164
+ end
165
+
166
+ #
167
+ # Assert that a +windows_service+ resource exists in the Chef run with the
168
+ # action +:restart+. Given a Chef Recipe that restarts "BITS" as a
169
+ # +windows_service+:
170
+ #
171
+ # windows_service 'BITS' do
172
+ # action :restart
173
+ # end
174
+ #
175
+ # To test the content rendered by a +windows_service+, see
176
+ # {ChefSpec::API::RenderFileMatchers}.
177
+ #
178
+ # The Examples section demonstrates the different ways to test a
179
+ # +windows_service+ resource with ChefSpec.
180
+ #
181
+ # @example Assert that a +windows_service+ was restarted
182
+ # expect(chef_run).to restart_windows_service('BITS')
183
+ #
184
+ # @example Assert that a +windows_service+ was restarted with predicate matchers
185
+ # expect(chef_run).to restart_windows_service('BITS').with_pattern('BI*')
186
+ #
187
+ # @example Assert that a +windows_service+ was restarted with attributes
188
+ # expect(chef_run).to restart_windows_service('BITS').with(pattern: 'BI*')
189
+ #
190
+ # @example Assert that a +windows_service+ was restarted using a regex
191
+ # expect(chef_run).to restart_windows_service('BITS').with(pattern: /(.+)/)
192
+ #
193
+ # @example Assert that a +windows_service+ was _not_ restarted
194
+ # expect(chef_run).to_not restart_windows_service('BITS')
195
+ #
196
+ #
197
+ # @param [String, Regex] resource_name
198
+ # the name of the resource to match
199
+ #
200
+ # @return [ChefSpec::Matchers::ResourceMatcher]
201
+ #
202
+ def restart_windows_service(resource_name)
203
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :restart, resource_name)
204
+ end
205
+
206
+ #
207
+ # Assert that a +windows_service+ resource exists in the Chef run with the
208
+ # action +:start+. Given a Chef Recipe that starts "BITS" as a
209
+ # +windows_service+:
210
+ #
211
+ # windows_service 'BITS' do
212
+ # action :start
213
+ # end
214
+ #
215
+ # To test the content rendered by a +windows_service+, see
216
+ # {ChefSpec::API::RenderFileMatchers}.
217
+ #
218
+ # The Examples section demonstrates the different ways to test a
219
+ # +windows_service+ resource with ChefSpec.
220
+ #
221
+ # @example Assert that a +windows_service+ was started
222
+ # expect(chef_run).to start_windows_service('BITS')
223
+ #
224
+ # @example Assert that a +windows_service+ was started with predicate matchers
225
+ # expect(chef_run).to start_windows_service('BITS').with_pattern('BI*')
226
+ #
227
+ # @example Assert that a +windows_service+ was started with attributes
228
+ # expect(chef_run).to start_windows_service('BITS').with(pattern: 'BI*')
229
+ #
230
+ # @example Assert that a +windows_service+ was started using a regex
231
+ # expect(chef_run).to start_windows_service('BITS').with(pattern: /(.+)/)
232
+ #
233
+ # @example Assert that a +windows_service+ was _not_ started
234
+ # expect(chef_run).to_not start_windows_service('BITS')
235
+ #
236
+ #
237
+ # @param [String, Regex] resource_name
238
+ # the name of the resource to match
239
+ #
240
+ # @return [ChefSpec::Matchers::ResourceMatcher]
241
+ #
242
+ def start_windows_service(resource_name)
243
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :start, resource_name)
244
+ end
245
+
246
+ #
247
+ # Assert that a +windows_service+ resource exists in the Chef run with the
248
+ # action +:stop+. Given a Chef Recipe that stops "BITS" as a
249
+ # +windows_service+:
250
+ #
251
+ # windows_service 'BITS' do
252
+ # action :stop
253
+ # end
254
+ #
255
+ # To test the content rendered by a +windows_service+, see
256
+ # {ChefSpec::API::RenderFileMatchers}.
257
+ #
258
+ # The Examples section demonstrates the different ways to test a
259
+ # +windows_service+ resource with ChefSpec.
260
+ #
261
+ # @example Assert that a +windows_service+ was stopped
262
+ # expect(chef_run).to stop_windows_service('BITS')
263
+ #
264
+ # @example Assert that a +windows_service+ was stopped with predicate matchers
265
+ # expect(chef_run).to stop_windows_service('BITS').with_pattern('BI*')
266
+ #
267
+ # @example Assert that a +windows_service+ was stopped with attributes
268
+ # expect(chef_run).to stop_windows_service('BITS').with(pattern: 'BI*')
269
+ #
270
+ # @example Assert that a +windows_service+ was stopped using a regex
271
+ # expect(chef_run).to stop_windows_service('BITS').with(pattern: /(.+)/)
272
+ #
273
+ # @example Assert that a +windows_service+ was _not_ stopped
274
+ # expect(chef_run).to_not stop_windows_service('BITS')
275
+ #
276
+ #
277
+ # @param [String, Regex] resource_name
278
+ # the name of the resource to match
279
+ #
280
+ # @return [ChefSpec::Matchers::ResourceMatcher]
281
+ #
282
+ def stop_windows_service(resource_name)
283
+ ChefSpec::Matchers::ResourceMatcher.new(:windows_service, :stop, resource_name)
284
+ end
285
+ end
286
+ end