chefspec 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +3 -3
  4. data/chefspec.gemspec +1 -1
  5. data/examples/bff_package/recipes/install.rb +13 -0
  6. data/examples/bff_package/recipes/purge.rb +13 -0
  7. data/examples/bff_package/recipes/remove.rb +13 -0
  8. data/examples/bff_package/recipes/upgrade.rb +13 -0
  9. data/examples/bff_package/spec/install_spec.rb +23 -0
  10. data/examples/bff_package/spec/purge_spec.rb +19 -0
  11. data/examples/bff_package/spec/remove_spec.rb +19 -0
  12. data/examples/bff_package/spec/upgrade_spec.rb +19 -0
  13. data/examples/homebrew_package/recipes/install.rb +13 -0
  14. data/examples/homebrew_package/recipes/purge.rb +13 -0
  15. data/examples/homebrew_package/recipes/remove.rb +13 -0
  16. data/examples/homebrew_package/recipes/upgrade.rb +13 -0
  17. data/examples/homebrew_package/spec/install_spec.rb +23 -0
  18. data/examples/homebrew_package/spec/purge_spec.rb +19 -0
  19. data/examples/homebrew_package/spec/remove_spec.rb +19 -0
  20. data/examples/homebrew_package/spec/upgrade_spec.rb +19 -0
  21. data/examples/launchd/recipes/create.rb +5 -0
  22. data/examples/launchd/recipes/create_if_missing.rb +3 -0
  23. data/examples/launchd/recipes/delete.rb +3 -0
  24. data/examples/launchd/recipes/disable.rb +3 -0
  25. data/examples/launchd/recipes/enable.rb +3 -0
  26. data/examples/launchd/spec/create_if_missing_spec.rb +10 -0
  27. data/examples/launchd/spec/create_spec.rb +14 -0
  28. data/examples/launchd/spec/delete_spec.rb +10 -0
  29. data/examples/launchd/spec/disable_spec.rb +10 -0
  30. data/examples/launchd/spec/enable_spec.rb +10 -0
  31. data/examples/openbsd_package/recipes/install.rb +13 -0
  32. data/examples/openbsd_package/recipes/purge.rb +13 -0
  33. data/examples/openbsd_package/recipes/remove.rb +13 -0
  34. data/examples/openbsd_package/recipes/upgrade.rb +13 -0
  35. data/examples/openbsd_package/spec/install_spec.rb +23 -0
  36. data/examples/openbsd_package/spec/purge_spec.rb +19 -0
  37. data/examples/openbsd_package/spec/remove_spec.rb +19 -0
  38. data/examples/openbsd_package/spec/upgrade_spec.rb +19 -0
  39. data/examples/osx_profile/recipes/install.rb +8 -0
  40. data/examples/osx_profile/recipes/remove.rb +8 -0
  41. data/examples/osx_profile/spec/install_spec.rb +15 -0
  42. data/examples/osx_profile/spec/remove_spec.rb +13 -0
  43. data/examples/paludis_package/recipes/install.rb +13 -0
  44. data/examples/paludis_package/recipes/purge.rb +13 -0
  45. data/examples/paludis_package/recipes/remove.rb +13 -0
  46. data/examples/paludis_package/recipes/upgrade.rb +13 -0
  47. data/examples/paludis_package/spec/install_spec.rb +23 -0
  48. data/examples/paludis_package/spec/purge_spec.rb +19 -0
  49. data/examples/paludis_package/spec/remove_spec.rb +19 -0
  50. data/examples/paludis_package/spec/upgrade_spec.rb +19 -0
  51. data/examples/ruby_block/recipes/create.rb +8 -0
  52. data/examples/ruby_block/spec/create_spec.rb +13 -0
  53. data/examples/script/recipes/run_ksh.rb +13 -0
  54. data/examples/script/spec/run_ksh_spec.rb +23 -0
  55. data/examples/solaris_package/recipes/upgrade.rb +13 -0
  56. data/examples/solaris_package/spec/upgrade_spec.rb +19 -0
  57. data/examples/systemd_unit/recipes/create.rb +3 -0
  58. data/examples/systemd_unit/recipes/delete.rb +3 -0
  59. data/examples/systemd_unit/recipes/disable.rb +3 -0
  60. data/examples/systemd_unit/recipes/enable.rb +3 -0
  61. data/examples/systemd_unit/recipes/mask.rb +3 -0
  62. data/examples/systemd_unit/recipes/reload_or_restart.rb +3 -0
  63. data/examples/systemd_unit/recipes/reload_or_try_restart.rb +3 -0
  64. data/examples/systemd_unit/recipes/restart.rb +3 -0
  65. data/examples/systemd_unit/recipes/start.rb +3 -0
  66. data/examples/systemd_unit/recipes/stop.rb +3 -0
  67. data/examples/systemd_unit/recipes/try_restart.rb +3 -0
  68. data/examples/systemd_unit/recipes/unmask.rb +3 -0
  69. data/examples/systemd_unit/spec/create_spec.rb +10 -0
  70. data/examples/systemd_unit/spec/delete_spec.rb +10 -0
  71. data/examples/systemd_unit/spec/disable_spec.rb +10 -0
  72. data/examples/systemd_unit/spec/enable_spec.rb +10 -0
  73. data/examples/systemd_unit/spec/mask_spec.rb +10 -0
  74. data/examples/systemd_unit/spec/reload_or_restart_spec.rb +10 -0
  75. data/examples/systemd_unit/spec/reload_or_try_restart_spec.rb +10 -0
  76. data/examples/systemd_unit/spec/restart_spec.rb +10 -0
  77. data/examples/systemd_unit/spec/start_spec.rb +10 -0
  78. data/examples/systemd_unit/spec/stop_spec.rb +10 -0
  79. data/examples/systemd_unit/spec/try_restart_spec.rb +10 -0
  80. data/examples/systemd_unit/spec/unmask_spec.rb +10 -0
  81. data/examples/zypper_package/recipes/install.rb +13 -0
  82. data/examples/zypper_package/recipes/purge.rb +13 -0
  83. data/examples/zypper_package/recipes/remove.rb +13 -0
  84. data/examples/zypper_package/recipes/upgrade.rb +13 -0
  85. data/examples/zypper_package/spec/install_spec.rb +23 -0
  86. data/examples/zypper_package/spec/purge_spec.rb +19 -0
  87. data/examples/zypper_package/spec/remove_spec.rb +19 -0
  88. data/examples/zypper_package/spec/upgrade_spec.rb +19 -0
  89. data/features/attributes.feature +1 -1
  90. data/features/bff_package.feature +12 -0
  91. data/features/chocolatey_package.feature +1 -0
  92. data/features/compile_time.feature +1 -1
  93. data/features/dsc_resource.feature +1 -0
  94. data/features/homebrew_package.feature +12 -0
  95. data/features/launchd.feature +23 -0
  96. data/features/openbsd_package.feature +14 -0
  97. data/features/osx_profile.feature +19 -0
  98. data/features/paludis_package.feature +14 -0
  99. data/features/roles.feature +1 -1
  100. data/features/ruby_block.feature +1 -0
  101. data/features/script.feature +8 -0
  102. data/features/solaris_package.feature +1 -0
  103. data/features/systemd_unit.feature +33 -0
  104. data/features/windows_package.feature +1 -0
  105. data/features/zypper_package.feature +18 -0
  106. data/lib/chefspec/api.rb +8 -0
  107. data/lib/chefspec/api/bff_package.rb +154 -0
  108. data/lib/chefspec/api/homebrew_package.rb +154 -0
  109. data/lib/chefspec/api/launchd.rb +151 -0
  110. data/lib/chefspec/api/openbsd_package.rb +155 -0
  111. data/lib/chefspec/api/osx_profile.rb +63 -0
  112. data/lib/chefspec/api/paludis_package.rb +155 -0
  113. data/lib/chefspec/api/ruby_block.rb +31 -0
  114. data/lib/chefspec/api/script.rb +39 -0
  115. data/lib/chefspec/api/solaris_package.rb +37 -0
  116. data/lib/chefspec/api/systemd_unit.rb +353 -0
  117. data/lib/chefspec/api/zypper_package.rb +154 -0
  118. data/lib/chefspec/version.rb +1 -1
  119. metadata +111 -3
@@ -33,5 +33,36 @@ module ChefSpec::API
33
33
  def run_ruby_block(resource_name)
34
34
  ChefSpec::Matchers::ResourceMatcher.new(:ruby_block, :run, resource_name)
35
35
  end
36
+
37
+ #
38
+ # Assert that a +ruby_block+ resource exists in the Chef run with the
39
+ # action +:create+. Given a Chef Recipe that runs "do_something" as a
40
+ # +ruby_block+:
41
+ #
42
+ # ruby_block 'do_something' do
43
+ # block do
44
+ # # ...
45
+ # end
46
+ # action :create
47
+ # end
48
+ #
49
+ # The Examples section demonstrates the different ways to test a
50
+ # +ruby_block+ resource with ChefSpec.
51
+ #
52
+ # @example Assert that a +ruby_block+ was run
53
+ # expect(chef_run).to create_ruby_block('do_something')
54
+ #
55
+ # @example Assert that a +ruby_block+ was _not_ run
56
+ # expect(chef_run).to_not create_ruby_block('do_something')
57
+ #
58
+ #
59
+ # @param [String, Regex] resource_name
60
+ # the name of the resource to match
61
+ #
62
+ # @return [ChefSpec::Matchers::ResourceMatcher]
63
+ #
64
+ def create_ruby_block(resource_name)
65
+ ChefSpec::Matchers::ResourceMatcher.new(:ruby_block, :create, resource_name)
66
+ end
36
67
  end
37
68
  end
@@ -1,6 +1,45 @@
1
1
  module ChefSpec::API
2
2
  # @since 1.0.0
3
3
  module ScriptMatchers
4
+ #
5
+ # Assert that a +ksh+ resource exists in the Chef run with the
6
+ # action +:run+. Given a Chef Recipe that runs "command" using
7
+ # +ksh+:
8
+ #
9
+ # ksh 'command' do
10
+ # action :run
11
+ # end
12
+ #
13
+ # The Examples section demonstrates the different ways to test a
14
+ # +ksh+ resource with ChefSpec.
15
+ #
16
+ # @example Assert that a +ksh+ was run
17
+ # expect(chef_run).to run_ksh('command')
18
+ #
19
+ # @example Assert that a +ksh+ was run with predicate matchers
20
+ # expect(chef_run).to run_ksh('command').with_cwd('/home')
21
+ #
22
+ # @example Assert that a +ksh+ was run with attributes
23
+ # expect(chef_run).to run_ksh('command').with(cwd: '/home')
24
+ #
25
+ # @example Assert that a +ksh+ was run using a regex
26
+ # expect(chef_run).to run_ksh('command').with(cwd: /\/(.+)/)
27
+ #
28
+ # @example Assert that a +ksh+ was _not_ run
29
+ # expect(chef_run).to_not run_ksh('command')
30
+ #
31
+ #
32
+ # @param [String, Regex] resource_name
33
+ # the name of the resource to match
34
+ #
35
+ # @return [ChefSpec::Matchers::ResourceMatcher]
36
+ #
37
+ def run_ksh(resource_name)
38
+ ChefSpec::Matchers::ResourceMatcher.new(:ksh, :run, resource_name)
39
+ end
40
+
41
+ ChefSpec.define_matcher :ksh
42
+
4
43
  #
5
44
  # Assert that a +bash+ resource exists in the Chef run with the
6
45
  # action +:run+. Given a Chef Recipe that runs "command" using
@@ -76,5 +76,42 @@ module ChefSpec::API
76
76
  def remove_solaris_package(resource_name)
77
77
  ChefSpec::Matchers::ResourceMatcher.new(:solaris_package, :remove, resource_name)
78
78
  end
79
+
80
+ #
81
+ # Assert that an +solaris_package+ resource exists in the Chef run with the
82
+ # action +:upgrade+. Given a Chef Recipe that upgrades "apache2" as an
83
+ # +solaris_package+:
84
+ #
85
+ # solaris_package 'apache2' do
86
+ # action :upgrade
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test an
90
+ # +solaris_package+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that an +solaris_package+ was upgradeed
93
+ # expect(chef_run).to upgrade_solaris_package('apache2')
94
+ #
95
+ # @example Assert that an +solaris_package+ was upgradeed with predicate matchers
96
+ # expect(chef_run).to upgrade_solaris_package('apache2').with_version('1.2.3')
97
+ #
98
+ # @example Assert that an +solaris_package+ was upgradeed with attributes
99
+ # expect(chef_run).to upgrade_solaris_package('apache2').with(version: '1.2.3')
100
+ #
101
+ # @example Assert that an +solaris_package+ was upgradeed using a regex
102
+ # expect(chef_run).to upgrade_solaris_package('apache2').with(version: /(\d+\.){2}\.\d+/)
103
+ #
104
+ # @example Assert that an +solaris_package+ was _not_ upgradeed
105
+ # expect(chef_run).to_not upgrade_solaris_package('apache2')
106
+ #
107
+ #
108
+ # @param [String, Regex] resource_name
109
+ # the name of the resource to match
110
+ #
111
+ # @return [ChefSpec::Matchers::ResourceMatcher]
112
+ #
113
+ def upgrade_solaris_package(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:solaris_package, :upgrade, resource_name)
115
+ end
79
116
  end
80
117
  end
@@ -0,0 +1,353 @@
1
+ module ChefSpec::API
2
+ # @since 5.1.0
3
+ module SystemdUnitMatchers
4
+ ChefSpec.define_matcher :systemd_unit
5
+
6
+ #
7
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
8
+ # action +:create+. Given a Chef Recipe that creates the systemd_unit
9
+ # "sysstat-collect.timer":
10
+ #
11
+ # systemd_unit 'sysstat-collect.timer' do
12
+ # action :create
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +systemd_unit+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +systemd_unit+ was created
19
+ # expect(chef_run).to create_systemd_unit('sysstat-collect.timer')
20
+ #
21
+ # @example Assert that a +systemd_unit+ was _not_ created
22
+ # expect(chef_run).to_not create_systemd_unit('sysstat-collect.timer')
23
+ #
24
+ #
25
+ # @param [String, Regex] resource_name
26
+ # the name of the resource to match
27
+ #
28
+ # @return [ChefSpec::Matchers::ResourceMatcher]
29
+ #
30
+
31
+ def create_systemd_unit(resource_name)
32
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :create, resource_name)
33
+ end
34
+
35
+ #
36
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
37
+ # action +:delete+. Given a Chef Recipe that deletes the systemd_unit
38
+ # "sysstat-collect.timer":
39
+ #
40
+ # systemd_unit 'sysstat-collect.timer' do
41
+ # action :delete
42
+ # end
43
+ #
44
+ # The Examples section demonstrates the different ways to test a
45
+ # +systemd_unit+ resource with ChefSpec.
46
+ #
47
+ # @example Assert that a +systemd_unit+ was deleted
48
+ # expect(chef_run).to delete_systemd_unit('sysstat-collect.timer')
49
+ #
50
+ # @example Assert that a +systemd_unit+ was _not_ deleted
51
+ # expect(chef_run).to_not delete_systemd_unit('sysstat-collect.timer')
52
+ #
53
+ #
54
+ # @param [String, Regex] resource_name
55
+ # the name of the resource to match
56
+ #
57
+ # @return [ChefSpec::Matchers::ResourceMatcher]
58
+ #
59
+
60
+ def delete_systemd_unit(resource_name)
61
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :delete, resource_name)
62
+ end
63
+
64
+ #
65
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
66
+ # action +:enable+. Given a Chef Recipe that enables the systemd_unit
67
+ # "sysstat-collect.timer":
68
+ #
69
+ # systemd_unit 'sysstat-collect.timer' do
70
+ # action :enables
71
+ # end
72
+ #
73
+ # The Examples section demonstrates the different ways to test a
74
+ # +systemd_unit+ resource with ChefSpec.
75
+ #
76
+ # @example Assert that a +systemd_unit+ was enabled
77
+ # expect(chef_run).to enable_systemd_unit('sysstat-collect.timer')
78
+ #
79
+ # @example Assert that a +systemd_unit+ was _not_ enabled
80
+ # expect(chef_run).to_not enable_systemd_unit('sysstat-collect.timer')
81
+ #
82
+ #
83
+ # @param [String, Regex] resource_name
84
+ # the name of the resource to match
85
+ #
86
+ # @return [ChefSpec::Matchers::ResourceMatcher]
87
+ #
88
+
89
+ def enable_systemd_unit(resource_name)
90
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :enable, resource_name)
91
+ end
92
+
93
+ #
94
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
95
+ # action +:disable+. Given a Chef Recipe that disables the systemd_unit
96
+ # "sysstat-collect.timer":
97
+ #
98
+ # systemd_unit 'sysstat-collect.timer' do
99
+ # action :disable
100
+ # end
101
+ #
102
+ # The Examples section demonstrates the different ways to test a
103
+ # +systemd_unit+ resource with ChefSpec.
104
+ #
105
+ # @example Assert that a +systemd_unit+ was disabled
106
+ # expect(chef_run).to disable_systemd_unit('sysstat-collect.timer')
107
+ #
108
+ # @example Assert that a +systemd_unit+ was _not_ disabled
109
+ # expect(chef_run).to_not disable_systemd_unit('sysstat-collect.timer')
110
+ #
111
+ #
112
+ # @param [String, Regex] resource_name
113
+ # the name of the resource to match
114
+ #
115
+ # @return [ChefSpec::Matchers::ResourceMatcher]
116
+ #
117
+
118
+ def disable_systemd_unit(resource_name)
119
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :disable, resource_name)
120
+ end
121
+
122
+ #
123
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
124
+ # action +:mask+. Given a Chef Recipe that masks the systemd_unit
125
+ # "sysstat-collect.timer":
126
+ #
127
+ # systemd_unit 'sysstat-collect.timer' do
128
+ # action :mask
129
+ # end
130
+ #
131
+ # The Examples section demonstrates the different ways to test a
132
+ # +systemd_unit+ resource with ChefSpec.
133
+ #
134
+ # @example Assert that a +systemd_unit+ was masked
135
+ # expect(chef_run).to mask_systemd_unit('sysstat-collect.timer')
136
+ #
137
+ # @example Assert that a +systemd_unit+ was _not_ masked
138
+ # expect(chef_run).to_not mask_systemd_unit('sysstat-collect.timer')
139
+ #
140
+ #
141
+ # @param [String, Regex] resource_name
142
+ # the name of the resource to match
143
+ #
144
+ # @return [ChefSpec::Matchers::ResourceMatcher]
145
+ #
146
+
147
+ def mask_systemd_unit(resource_name)
148
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :mask, resource_name)
149
+ end
150
+
151
+ #
152
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
153
+ # action +:unmask+. Given a Chef Recipe that masks the systemd_unit
154
+ # "sysstat-collect.timer":
155
+ #
156
+ # systemd_unit 'sysstat-collect.timer' do
157
+ # action :unmask
158
+ # end
159
+ #
160
+ # The Examples section demonstrates the different ways to test a
161
+ # +systemd_unit+ resource with ChefSpec.
162
+ #
163
+ # @example Assert that a +systemd_unit+ was unmasked
164
+ # expect(chef_run).to unmask_systemd_unit('sysstat-collect.timer')
165
+ #
166
+ # @example Assert that a +systemd_unit+ was _not_ unmasked
167
+ # expect(chef_run).to_not unmask_systemd_unit('sysstat-collect.timer')
168
+ #
169
+ #
170
+ # @param [String, Regex] resource_name
171
+ # the name of the resource to match
172
+ #
173
+ # @return [ChefSpec::Matchers::ResourceMatcher]
174
+ #
175
+
176
+ def unmask_systemd_unit(resource_name)
177
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :unmask, resource_name)
178
+ end
179
+
180
+ #
181
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
182
+ # action +:start+. Given a Chef Recipe that starts the systemd_unit
183
+ # "sysstat-collect.timer":
184
+ #
185
+ # systemd_unit 'sysstat-collect.timer' do
186
+ # action :start
187
+ # end
188
+ #
189
+ # The Examples section demonstrates the different ways to test a
190
+ # +systemd_unit+ resource with ChefSpec.
191
+ #
192
+ # @example Assert that a +systemd_unit+ was started
193
+ # expect(chef_run).to start_systemd_unit('sysstat-collect.timer')
194
+ #
195
+ # @example Assert that a +systemd_unit+ was _not_ started
196
+ # expect(chef_run).to_not start_systemd_unit('sysstat-collect.timer')
197
+ #
198
+ #
199
+ # @param [String, Regex] resource_name
200
+ # the name of the resource to match
201
+ #
202
+ # @return [ChefSpec::Matchers::ResourceMatcher]
203
+ #
204
+
205
+ def start_systemd_unit(resource_name)
206
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :start, resource_name)
207
+ end
208
+
209
+ #
210
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
211
+ # action +:stop+. Given a Chef Recipe that stops the systemd_unit
212
+ # "sysstat-collect.timer":
213
+ #
214
+ # systemd_unit 'sysstat-collect.timer' do
215
+ # action :stop
216
+ # end
217
+ #
218
+ # The Examples section demonstrates the different ways to test a
219
+ # +systemd_unit+ resource with ChefSpec.
220
+ #
221
+ # @example Assert that a +systemd_unit+ was stopped
222
+ # expect(chef_run).to stop_systemd_unit('sysstat-collect.timer')
223
+ #
224
+ # @example Assert that a +systemd_unit+ was _not_ stopped
225
+ # expect(chef_run).to_not stop_systemd_unit('sysstat-collect.timer')
226
+ #
227
+ #
228
+ # @param [String, Regex] resource_name
229
+ # the name of the resource to match
230
+ #
231
+ # @return [ChefSpec::Matchers::ResourceMatcher]
232
+ #
233
+
234
+ def stop_systemd_unit(resource_name)
235
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :stop, resource_name)
236
+ end
237
+
238
+ #
239
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
240
+ # action +:restart+. Given a Chef Recipe that restarts the systemd_unit
241
+ # "sysstat-collect.timer":
242
+ #
243
+ # systemd_unit 'sysstat-collect.timer' do
244
+ # action :restart
245
+ # end
246
+ #
247
+ # The Examples section demonstrates the different ways to test a
248
+ # +systemd_unit+ resource with ChefSpec.
249
+ #
250
+ # @example Assert that a +systemd_unit+ was restarted
251
+ # expect(chef_run).to restart_systemd_unit('sysstat-collect.timer')
252
+ #
253
+ # @example Assert that a +systemd_unit+ was _not_ restarted
254
+ # expect(chef_run).to_not restart_systemd_unit('sysstat-collect.timer')
255
+ #
256
+ #
257
+ # @param [String, Regex] resource_name
258
+ # the name of the resource to match
259
+ #
260
+ # @return [ChefSpec::Matchers::ResourceMatcher]
261
+ #
262
+
263
+ def restart_systemd_unit(resource_name)
264
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :restart, resource_name)
265
+ end
266
+
267
+ #
268
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
269
+ # action +:try_restart+. Given a Chef Recipe that tries to restarts the
270
+ # systemd_unit "sysstat-collect.timer":
271
+ #
272
+ # systemd_unit 'sysstat-collect.timer' do
273
+ # action :try_restart
274
+ # end
275
+ #
276
+ # The Examples section demonstrates the different ways to test a
277
+ # +systemd_unit+ resource with ChefSpec.
278
+ #
279
+ # @example Assert that a +systemd_unit+ was try_restart'd
280
+ # expect(chef_run).to try_restart_systemd_unit('sysstat-collect.timer')
281
+ #
282
+ # @example Assert that a +systemd_unit+ was _not_ try_restart'd
283
+ # expect(chef_run).to_not try_restart_systemd_unit('sysstat-collect.timer')
284
+ #
285
+ #
286
+ # @param [String, Regex] resource_name
287
+ # the name of the resource to match
288
+ #
289
+ # @return [ChefSpec::Matchers::ResourceMatcher]
290
+ #
291
+
292
+ def try_restart_systemd_unit(resource_name)
293
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :try_restart, resource_name)
294
+ end
295
+
296
+ #
297
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
298
+ # action +:reload_or_restart+. Given a Chef Recipe that reloads or restarts
299
+ # the systemd_unit "sysstat-collect.timer":
300
+ #
301
+ # systemd_unit 'sysstat-collect.timer' do
302
+ # action :reload_or_restart
303
+ # end
304
+ #
305
+ # The Examples section demonstrates the different ways to test a
306
+ # +systemd_unit+ resource with ChefSpec.
307
+ #
308
+ # @example Assert that a +systemd_unit+ was reloaded or restarted
309
+ # expect(chef_run).to reload_or_restart_systemd_unit('sysstat-collect.timer')
310
+ #
311
+ # @example Assert that a +systemd_unit+ was _not_ reloaded or restarted
312
+ # expect(chef_run).to_not reload_or_restart_systemd_unit('sysstat-collect.timer')
313
+ #
314
+ #
315
+ # @param [String, Regex] resource_name
316
+ # the name of the resource to match
317
+ #
318
+ # @return [ChefSpec::Matchers::ResourceMatcher]
319
+ #
320
+
321
+ def reload_or_restart_systemd_unit(resource_name)
322
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :reload_or_restart, resource_name)
323
+ end
324
+ #
325
+ # Assert that a +systemd_unit+ resource exists in the Chef run with the
326
+ # action +:reload_or_try_restart+. Given a Chef Recipe that reloads or attempts
327
+ # to restart the systemd_unit "sysstat-collect.timer":
328
+ #
329
+ # systemd_unit 'sysstat-collect.timer' do
330
+ # action :reload_or_try_restart
331
+ # end
332
+ #
333
+ # The Examples section demonstrates the different ways to test a
334
+ # +systemd_unit+ resource with ChefSpec.
335
+ #
336
+ # @example Assert that a +systemd_unit+ was reloaded or try restarted
337
+ # expect(chef_run).to reload_or_try_restart_systemd_unit('sysstat-collect.timer')
338
+ #
339
+ # @example Assert that a +systemd_unit+ was _not_ reloaded or try restarted
340
+ # expect(chef_run).to_not reload_or_try_restart_systemd_unit('sysstat-collect.timer')
341
+ #
342
+ #
343
+ # @param [String, Regex] resource_name
344
+ # the name of the resource to match
345
+ #
346
+ # @return [ChefSpec::Matchers::ResourceMatcher]
347
+ #
348
+
349
+ def reload_or_try_restart_systemd_unit(resource_name)
350
+ ChefSpec::Matchers::ResourceMatcher.new(:systemd_unit, :reload_or_try_restart, resource_name)
351
+ end
352
+ end
353
+ end