chefspec 4.2.0 → 4.7.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +39 -16
  4. data/CHANGELOG.md +136 -72
  5. data/README.md +187 -13
  6. data/chefspec.gemspec +5 -5
  7. data/examples/batch/spec/run_spec.rb +5 -0
  8. data/examples/chef_gem/recipes/install.rb +8 -3
  9. data/examples/chef_gem/recipes/purge.rb +6 -3
  10. data/examples/chef_gem/recipes/reconfig.rb +6 -3
  11. data/examples/chef_gem/recipes/remove.rb +6 -3
  12. data/examples/chef_gem/recipes/upgrade.rb +6 -3
  13. data/examples/chocolatey_package/recipes/install.rb +6 -0
  14. data/examples/chocolatey_package/recipes/remove.rb +8 -0
  15. data/examples/chocolatey_package/recipes/upgrade.rb +8 -0
  16. data/examples/chocolatey_package/spec/install_spec.rb +21 -0
  17. data/examples/chocolatey_package/spec/remove_spec.rb +20 -0
  18. data/examples/chocolatey_package/spec/upgrade_spec.rb +20 -0
  19. data/examples/directory/recipes/create.rb +4 -0
  20. data/examples/directory/spec/create_spec.rb +4 -0
  21. data/examples/dpkg_package/spec/install_spec.rb +5 -0
  22. data/examples/dpkg_package/spec/purge_spec.rb +5 -0
  23. data/examples/dpkg_package/spec/remove_spec.rb +5 -0
  24. data/examples/dsc_resource/recipes/default.rb +20 -0
  25. data/examples/dsc_resource/spec/default_spec.rb +40 -0
  26. data/examples/env/spec/create_spec.rb +5 -0
  27. data/examples/env/spec/delete_spec.rb +5 -0
  28. data/examples/env/spec/modify_spec.rb +5 -0
  29. data/examples/ips_package/spec/install_spec.rb +5 -0
  30. data/examples/ips_package/spec/remove_spec.rb +5 -0
  31. data/examples/ips_package/spec/upgrade_spec.rb +5 -0
  32. data/examples/package/recipes/install.rb +4 -0
  33. data/examples/package/recipes/purge.rb +4 -0
  34. data/examples/package/recipes/reconfig.rb +4 -0
  35. data/examples/package/recipes/remove.rb +4 -0
  36. data/examples/package/recipes/upgrade.rb +4 -0
  37. data/examples/package/spec/install_spec.rb +4 -0
  38. data/examples/package/spec/purge_spec.rb +4 -0
  39. data/examples/package/spec/reconfig_spec.rb +4 -0
  40. data/examples/package/spec/remove_spec.rb +4 -0
  41. data/examples/package/spec/upgrade_spec.rb +4 -0
  42. data/examples/pacman_package/spec/install_spec.rb +5 -0
  43. data/examples/pacman_package/spec/purge_spec.rb +5 -0
  44. data/examples/pacman_package/spec/remove_spec.rb +5 -0
  45. data/examples/pacman_package/spec/upgrade_spec.rb +5 -0
  46. data/examples/powershell_script/spec/run_spec.rb +5 -0
  47. data/examples/reboot/recipes/cancel.rb +3 -0
  48. data/examples/reboot/recipes/now.rb +3 -0
  49. data/examples/reboot/recipes/request.rb +3 -0
  50. data/examples/reboot/spec/cancel_spec.rb +10 -0
  51. data/examples/reboot/spec/now_spec.rb +10 -0
  52. data/examples/reboot/spec/request_spec.rb +10 -0
  53. data/examples/render_file/spec/default_spec.rb +40 -0
  54. data/examples/rpm_package/spec/install_spec.rb +5 -0
  55. data/examples/rpm_package/spec/remove_spec.rb +5 -0
  56. data/examples/rpm_package/spec/upgrade_spec.rb +5 -0
  57. data/examples/server/spec/node_spec.rb +1 -1
  58. data/examples/server/spec/search_spec.rb +4 -0
  59. data/examples/step_into/providers/provides.rb +3 -0
  60. data/examples/step_into/recipes/default.rb +2 -0
  61. data/examples/step_into/resources/lwrp.rb +1 -1
  62. data/examples/step_into/resources/provides.rb +6 -0
  63. data/examples/step_into/spec/default_spec.rb +10 -2
  64. data/examples/windows_package/recipes/install.rb +13 -0
  65. data/examples/windows_package/recipes/remove.rb +13 -0
  66. data/examples/windows_package/spec/install_spec.rb +24 -0
  67. data/examples/windows_package/spec/remove_spec.rb +24 -0
  68. data/examples/windows_service/recipes/configure_startup.rb +13 -0
  69. data/examples/windows_service/recipes/disable.rb +13 -0
  70. data/examples/windows_service/recipes/enable.rb +13 -0
  71. data/examples/windows_service/recipes/reload.rb +13 -0
  72. data/examples/windows_service/recipes/restart.rb +13 -0
  73. data/examples/windows_service/recipes/start.rb +13 -0
  74. data/examples/windows_service/recipes/stop.rb +13 -0
  75. data/examples/windows_service/spec/configure_startup_spec.rb +24 -0
  76. data/examples/windows_service/spec/disable_spec.rb +24 -0
  77. data/examples/windows_service/spec/enable_spec.rb +24 -0
  78. data/examples/windows_service/spec/reload_spec.rb +24 -0
  79. data/examples/windows_service/spec/restart_spec.rb +24 -0
  80. data/examples/windows_service/spec/start_spec.rb +24 -0
  81. data/examples/windows_service/spec/stop_spec.rb +24 -0
  82. data/features/chocolatey_package.feature +29 -0
  83. data/features/dsc_resource.feature +18 -0
  84. data/features/reboot.feature +19 -0
  85. data/features/step_definitions/background_steps.rb +4 -1
  86. data/features/step_into.feature +7 -0
  87. data/features/support/env.rb +5 -4
  88. data/features/windows_package.feature +24 -0
  89. data/features/windows_service.feature +23 -0
  90. data/gemfiles/chefspec.gemfile +9 -0
  91. data/lib/chefspec/api/chocolatey_package.rb +107 -0
  92. data/lib/chefspec/api/directory.rb +10 -10
  93. data/lib/chefspec/api/dsc_resource.rb +49 -0
  94. data/lib/chefspec/api/group.rb +5 -5
  95. data/lib/chefspec/api/link.rb +10 -10
  96. data/lib/chefspec/api/mdadm.rb +5 -5
  97. data/lib/chefspec/api/reboot.rb +18 -0
  98. data/lib/chefspec/api/remote_directory.rb +10 -10
  99. data/lib/chefspec/api/route.rb +5 -5
  100. data/lib/chefspec/api/user.rb +5 -5
  101. data/lib/chefspec/api/windows_package.rb +86 -0
  102. data/lib/chefspec/api/windows_service.rb +286 -0
  103. data/lib/chefspec/api.rb +5 -0
  104. data/lib/chefspec/berkshelf.rb +7 -1
  105. data/lib/chefspec/coverage/filters.rb +2 -1
  106. data/lib/chefspec/coverage.rb +1 -1
  107. data/lib/chefspec/deprecations.rb +6 -2
  108. data/lib/chefspec/errors.rb +4 -0
  109. data/lib/chefspec/extensions/chef/lwrp_base.rb +23 -0
  110. data/lib/chefspec/file_cache_path_proxy.rb +15 -0
  111. data/lib/chefspec/matchers/render_file_matcher.rb +20 -2
  112. data/lib/chefspec/matchers/resource_matcher.rb +9 -2
  113. data/lib/chefspec/mixins/normalize.rb +7 -1
  114. data/lib/chefspec/policyfile.rb +62 -0
  115. data/lib/chefspec/renderer.rb +2 -4
  116. data/lib/chefspec/rspec.rb +3 -0
  117. data/lib/chefspec/server_methods.rb +1 -0
  118. data/lib/chefspec/server_runner.rb +9 -0
  119. data/lib/chefspec/solo_runner.rb +13 -3
  120. data/lib/chefspec/version.rb +1 -1
  121. data/lib/chefspec.rb +1 -1
  122. data/spec/unit/coverage/filters_spec.rb +60 -0
  123. data/spec/unit/deprecations_spec.rb +3 -1
  124. data/spec/unit/macros_spec.rb +1 -1
  125. data/spec/unit/matchers/render_file_matcher_spec.rb +11 -0
  126. data/spec/unit/renderer_spec.rb +20 -2
  127. data/spec/unit/server_runner_spec.rb +28 -0
  128. data/spec/unit/solo_runner_spec.rb +3 -1
  129. data/templates/errors/invalid_berkshelf_options.erb +4 -0
  130. data/templates/errors/may_need_to_specify_platform.erb +25 -0
  131. metadata +72 -18
  132. data/gemfiles/chef-11.14.0.gemfile +0 -5
  133. data/gemfiles/chef-11.16.0.gemfile +0 -5
  134. data/gemfiles/chef-12.0.0.gemfile +0 -5
  135. data/gemfiles/chef-master.gemfile +0 -5
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::configure_startup' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'configures startup for a windows_service with an explicit action' do
12
+ expect(chef_run).to configure_startup_windows_service('explicit_action')
13
+ expect(chef_run).to_not configure_startup_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'configures startup for a windows_service with attributes' do
17
+ expect(chef_run).to configure_startup_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not configure_startup_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'configures startup for a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to configure_startup_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::disable' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'disables a windows_service with an explicit action' do
12
+ expect(chef_run).to disable_windows_service('explicit_action')
13
+ expect(chef_run).to_not disable_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'disables a windows_service with attributes' do
17
+ expect(chef_run).to disable_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not disable_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'disables a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to disable_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::enable' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'enables a windows_service with an explicit action' do
12
+ expect(chef_run).to enable_windows_service('explicit_action')
13
+ expect(chef_run).to_not enable_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'enables a windows_service with attributes' do
17
+ expect(chef_run).to enable_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not enable_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'enables a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to enable_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::reload' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'reloads a windows_service with an explicit action' do
12
+ expect(chef_run).to reload_windows_service('explicit_action')
13
+ expect(chef_run).to_not reload_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'reloads a windows_service with attributes' do
17
+ expect(chef_run).to reload_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not reload_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'reloads a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to reload_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::restart' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'restarts a windows_service with an explicit action' do
12
+ expect(chef_run).to restart_windows_service('explicit_action')
13
+ expect(chef_run).to_not restart_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'restarts a windows_service with attributes' do
17
+ expect(chef_run).to restart_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not restart_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'restarts a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to restart_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::start' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'starts a windows_service with an explicit action' do
12
+ expect(chef_run).to start_windows_service('explicit_action')
13
+ expect(chef_run).to_not start_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'starts a windows_service with attributes' do
17
+ expect(chef_run).to start_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not start_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'starts a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to start_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'chefspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.platform = 'windows'
5
+ config.version = '2012R2'
6
+ end
7
+
8
+ describe 'windows_service::stop' do
9
+ let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
10
+
11
+ it 'stops a windows_service with an explicit action' do
12
+ expect(chef_run).to stop_windows_service('explicit_action')
13
+ expect(chef_run).to_not stop_windows_service('not_explicit_action')
14
+ end
15
+
16
+ it 'stops a windows_service with attributes' do
17
+ expect(chef_run).to stop_windows_service('with_attributes').with(pattern: 'pattern')
18
+ expect(chef_run).to_not stop_windows_service('with_attributes').with(pattern: 'bacon')
19
+ end
20
+
21
+ it 'stops a windows_service when specifying the identity attribute' do
22
+ expect(chef_run).to stop_windows_service('identity_attribute')
23
+ end
24
+ end
@@ -0,0 +1,29 @@
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
+ @not_chef_12_0_3
9
+ @not_chef_12_1_0
10
+ @not_chef_12_1_1
11
+ @not_chef_12_1_2
12
+ @not_chef_12_2_1
13
+ @not_chef_12_3_0
14
+ @not_chef_12_4_0
15
+ @not_chef_12_4_3
16
+ @not_chef_12_5_1
17
+ @not_chef_12_6_0
18
+ Feature: The chocolatey_package matcher
19
+ Background:
20
+ * I am using the "chocolatey_package" cookbook
21
+
22
+ Scenario Outline: Running specs
23
+ * I successfully run `rspec spec/<Matcher>_spec.rb`
24
+ * the output should contain "0 failures"
25
+ Examples:
26
+ | Matcher |
27
+ | install |
28
+ | remove |
29
+ | upgrade |
@@ -0,0 +1,18 @@
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
+ @not_chef_12_0_3
9
+ @not_chef_12_1_0
10
+ @not_chef_12_1_1
11
+ @not_chef_12_1_2
12
+ Feature: The dsc_resource matcher
13
+ Background:
14
+ * I am using the "dsc_resource" cookbook
15
+
16
+ Scenario: Running specs
17
+ * I successfully run `rspec spec/default_spec.rb`
18
+ * the output should contain "0 failures"
@@ -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 |
@@ -1,4 +1,7 @@
1
1
  Given /^I am using the "(.+)" cookbook$/ do |cookbook|
2
- FileUtils.cp_r(File.join('examples', cookbook), current_dir)
2
+ source = File.join('examples', cookbook)
3
+ destination = expand_path('.')
4
+
5
+ FileUtils.cp_r(source, destination)
3
6
  cd(cookbook)
4
7
  end
@@ -1,3 +1,10 @@
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
1
8
  Feature: The step_into matcher
2
9
  Background:
3
10
  * I am using the "step_into" cookbook
@@ -8,12 +8,13 @@ require 'chefspec'
8
8
  require_relative 'executor'
9
9
 
10
10
  Before do
11
- FileUtils.mkdir_p(current_dir)
12
- FileUtils.cp_r('examples', current_dir)
11
+ FileUtils.mkdir_p(expand_path('.'))
13
12
 
14
13
  # Use InProcess testing by default
15
- Aruba::InProcess.main_class = ChefSpec::Executor
16
- Aruba.process = Aruba::InProcess
14
+ Aruba.configure do |config|
15
+ config.command_launcher = :in_process
16
+ config.main_class = ChefSpec::Executor
17
+ end
17
18
 
18
19
  # Need to reload this on each run because RSpec.reset (called by the
19
20
  # RSpec::Runner) removes our configurations :(
@@ -0,0 +1,24 @@
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
+ @not_chef_12_0_3
9
+ @not_chef_12_1_0
10
+ @not_chef_12_1_1
11
+ @not_chef_12_1_2
12
+ @not_chef_12_2_1
13
+ @not_chef_12_3_0
14
+ Feature: The windows_package matcher
15
+ Background:
16
+ * I am using the "windows_package" cookbook
17
+
18
+ Scenario Outline: Running specs
19
+ * I successfully run `rspec spec/<Matcher>_spec.rb`
20
+ * the output should contain "0 failures"
21
+ Examples:
22
+ | Matcher |
23
+ | install |
24
+ | remove |
@@ -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: '..'
@@ -0,0 +1,107 @@
1
+ module ChefSpec::API
2
+ # @since 4.6.0
3
+ module ChocolateyPackageMatchers
4
+ ChefSpec.define_matcher :chocolatey_package
5
+ #
6
+ # Assert that a +chocolatey_package+ resource exists in the Chef run with the
7
+ # action +:install+. Given a Chef Recipe that installs "7zip" as a
8
+ # +chocolatey_package+:
9
+ #
10
+ # chocolatey_package '7zip' do
11
+ # action :install
12
+ # end
13
+ #
14
+ # The Examples section demonstrates the different ways to test a
15
+ # +chocolatey_package+ resource with ChefSpec.
16
+ #
17
+ # @example Assert that a +chocolatey_package+ was installed
18
+ # expect(chef_run).to install_chocolatey_package('7zip')
19
+ #
20
+ # @example Assert that a +chocolatey_package+ was installed with attributes
21
+ # expect(chef_run).to install_chocolatey_package('git').with(
22
+ # version: %w(2.7.1),
23
+ # options: '--params /GitAndUnixToolsOnPath'
24
+ # )
25
+ #
26
+ # @example Assert that a +chocolatey_package+ was _not_ installed
27
+ # expect(chef_run).to_not install_chocolatey_package('flashplayeractivex')
28
+ #
29
+ # @param [String, Regex] resource_name
30
+ # the name of the resource to match
31
+ #
32
+ # @return [ChefSpec::Matchers::ResourceMatcher]
33
+ #
34
+ def install_chocolatey_package(resource_name)
35
+ ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :install, resource_name)
36
+ end
37
+
38
+ #
39
+ # Assert that a +chocolatey_package+ resource exists in the Chef run with the
40
+ # action +:remove+. Given a Chef Recipe that removes "7zip" as a
41
+ # +chocolatey_package+:
42
+ #
43
+ # chocolatey_package '7zip' do
44
+ # action :remove
45
+ # end
46
+ #
47
+ # To test the content rendered by a +chocolatey_package+, see
48
+ # {ChefSpec::API::RenderFileMatchers}.
49
+ #
50
+ # The Examples section demonstrates the different ways to test a
51
+ # +chocolatey_package+ resource with ChefSpec.
52
+ #
53
+ # @example Assert that a +chocolatey_package+ was removed
54
+ # expect(chef_run).to remove_chocolatey_package('7zip')
55
+ #
56
+ # @example Assert that a specific +chocolatey_package+ version was removed
57
+ # expect(chef_run).to remove_chocolatey_package('7zip').with(
58
+ # version: %w(15.14)
59
+ # )
60
+ #
61
+ # @example Assert that a +chocolatey_package+ was _not_ removed
62
+ # expect(chef_run).to_not remove_chocolatey_package('7zip')
63
+ #
64
+ #
65
+ # @param [String, Regex] resource_name
66
+ # the name of the resource to match
67
+ #
68
+ # @return [ChefSpec::Matchers::ResourceMatcher]
69
+ #
70
+ def remove_chocolatey_package(resource_name)
71
+ ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :remove, resource_name)
72
+ end
73
+
74
+ #
75
+ # Assert that a +chocolatey_package+ resource exists in the Chef run with the
76
+ # action +:upgrade+. Given a Chef Recipe that upgrades "7zip" as a
77
+ # +chocolatey_package+:
78
+ #
79
+ # chocolatey_package '7zip' do
80
+ # action :upgrade
81
+ # end
82
+ #
83
+ # The Examples section demonstrates the different ways to test a
84
+ # +chocolatey_package+ resource with ChefSpec.
85
+ #
86
+ # @example Assert that a +chocolatey_package+ was upgraded
87
+ # expect(chef_run).to upgrade_chocolatey_package('7zip')
88
+ #
89
+ # @example Assert that a +chocolatey_package+ was upgraded with attributes
90
+ # expect(chef_run).to upgrade_chocolatey_package('git').with(
91
+ # version: %w(2.7.1),
92
+ # options: '-params "/GitAndUnixToolsOnPath"'
93
+ # )
94
+ #
95
+ # @example Assert that a +chocolatey_package+ was _not_ upgraded
96
+ # expect(chef_run).to_not upgrade_chocolatey_package('flashplayeractivex')
97
+ #
98
+ # @param [String, Regex] resource_name
99
+ # the name of the resource to match
100
+ #
101
+ # @return [ChefSpec::Matchers::ResourceMatcher]
102
+ #
103
+ def upgrade_chocolatey_package(resource_name)
104
+ ChefSpec::Matchers::ResourceMatcher.new(:chocolatey_package, :upgrade, resource_name)
105
+ end
106
+ end
107
+ end
@@ -15,19 +15,19 @@ module ChefSpec::API
15
15
  # The Examples section demonstrates the different ways to test a
16
16
  # +directory+ resource with ChefSpec.
17
17
  #
18
- # @example Assert that a +directory+ was createed
18
+ # @example Assert that a +directory+ was created
19
19
  # expect(chef_run).to create_directory('/tmp')
20
20
  #
21
- # @example Assert that a +directory+ was createed with predicate matchers
21
+ # @example Assert that a +directory+ was created with predicate matchers
22
22
  # expect(chef_run).to create_directory('/tmp').with_user('svargo')
23
23
  #
24
- # @example Assert that a +directory+ was createed with attributes
24
+ # @example Assert that a +directory+ was created with attributes
25
25
  # expect(chef_run).to create_directory('/tmp').with(user: 'svargo')
26
26
  #
27
- # @example Assert that a +directory+ was createed using a regex
27
+ # @example Assert that a +directory+ was created using a regex
28
28
  # expect(chef_run).to create_directory('/tmp').with(user: /sva(.+)/)
29
29
  #
30
- # @example Assert that a +directory+ was _not_ createed
30
+ # @example Assert that a +directory+ was _not_ created
31
31
  # expect(chef_run).to_not create_directory('/tmp')
32
32
  #
33
33
  #
@@ -52,19 +52,19 @@ module ChefSpec::API
52
52
  # The Examples section demonstrates the different ways to test a
53
53
  # +directory+ resource with ChefSpec.
54
54
  #
55
- # @example Assert that a +directory+ was deleteed
55
+ # @example Assert that a +directory+ was deleted
56
56
  # expect(chef_run).to delete_directory('/tmp')
57
57
  #
58
- # @example Assert that a +directory+ was deleteed with predicate matchers
58
+ # @example Assert that a +directory+ was deleted with predicate matchers
59
59
  # expect(chef_run).to delete_directory('/tmp').with_user('svargo')
60
60
  #
61
- # @example Assert that a +directory+ was deleteed with attributes
61
+ # @example Assert that a +directory+ was deleted with attributes
62
62
  # expect(chef_run).to delete_directory('/tmp').with(user: 'svargo')
63
63
  #
64
- # @example Assert that a +directory+ was deleteed using a regex
64
+ # @example Assert that a +directory+ was deleted using a regex
65
65
  # expect(chef_run).to delete_directory('/tmp').with(user: /sva(.+)/)
66
66
  #
67
- # @example Assert that a +directory+ was _not_ deleteed
67
+ # @example Assert that a +directory+ was _not_ deleted
68
68
  # expect(chef_run).to_not delete_directory('/tmp')
69
69
  #
70
70
  #
@@ -0,0 +1,49 @@
1
+ module ChefSpec::API
2
+ # @since 4.3.0
3
+ module DscResourceMatchers
4
+ ChefSpec.define_matcher :dsc_resource
5
+
6
+ #
7
+ # Assert that a +dsc_resource+ resource exists in the Chef run with the
8
+ # action +:run+. Given a Chef Recipe that installs "zip" as a
9
+ # +dsc_resource+:
10
+ #
11
+ # dsc_resource 'zip' do
12
+ # resource :archive
13
+ # property :ensure, 'Present'
14
+ # property :path, "C:\Users\Public\Documents\example.zip"
15
+ # property :destination, "C:\Users\Public\Documents\ExtractionPath"
16
+ # end
17
+ #
18
+ # To test the content rendered by a +dsc_resource+, see
19
+ # {ChefSpec::API::RenderFileMatchers}.
20
+ #
21
+ # The Examples section demonstrates the different ways to test a
22
+ # +dsc_resource+ resource with ChefSpec.
23
+ #
24
+ # @example Assert that a +dsc_resource+ was installed
25
+ # expect(chef_run).to run_dsc_resource('zip')
26
+ #
27
+ # @example Assert that a +dsc_resource+ was installed with predicate matchers
28
+ # expect(chef_run).to run_dsc_resource('zip').with_resource(:archive)
29
+ #
30
+ # @example Assert that a +dsc_resource+ was installed with attributes
31
+ # expect(chef_run).to run_dsc_resource('zip').with(resource: :archive)
32
+ #
33
+ # @example Assert that a +dsc_resource+ was installed using a regex
34
+ # expect(chef_run).to run_dsc_resource('zip').with(resource: /:arch(.+)/)
35
+ #
36
+ # @example Assert that a +dsc_resource+ was _not_ installed
37
+ # expect(chef_run).to_not run_dsc_resource('zip')
38
+ #
39
+ #
40
+ # @param [String, Regex] resource_name
41
+ # the name of the resource to match
42
+ #
43
+ # @return [ChefSpec::Matchers::ResourceMatcher]
44
+ #
45
+ def run_dsc_resource(resource_name)
46
+ ChefSpec::Matchers::ResourceMatcher.new(:dsc_resource, :run, resource_name)
47
+ end
48
+ end
49
+ end
@@ -15,19 +15,19 @@ module ChefSpec::API
15
15
  # The Examples section demonstrates the different ways to test a
16
16
  # +group+ resource with ChefSpec.
17
17
  #
18
- # @example Assert that a +group+ was createed
18
+ # @example Assert that a +group+ was created
19
19
  # expect(chef_run).to create_group('apache2')
20
20
  #
21
- # @example Assert that a +group+ was createed with predicate matchers
21
+ # @example Assert that a +group+ was created with predicate matchers
22
22
  # expect(chef_run).to create_group('apache2').with_gid(1234)
23
23
  #
24
- # @example Assert that a +group+ was createed with attributes
24
+ # @example Assert that a +group+ was created with attributes
25
25
  # expect(chef_run).to create_group('apache2').with(gid: 1234)
26
26
  #
27
- # @example Assert that a +group+ was createed using a regex
27
+ # @example Assert that a +group+ was created using a regex
28
28
  # expect(chef_run).to create_group('apache2').with(gid: /\d+/)
29
29
  #
30
- # @example Assert that a +group+ was _not_ createed
30
+ # @example Assert that a +group+ was _not_ created
31
31
  # expect(chef_run).to_not create_group('apache2')
32
32
  #
33
33
  #
@@ -15,19 +15,19 @@ module ChefSpec::API
15
15
  # The Examples section demonstrates the different ways to test a
16
16
  # +link+ resource with ChefSpec.
17
17
  #
18
- # @example Assert that a +link+ was createed
18
+ # @example Assert that a +link+ was created
19
19
  # expect(chef_run).to create_link('/tmp')
20
20
  #
21
- # @example Assert that a +link+ was createed with predicate matchers
21
+ # @example Assert that a +link+ was created with predicate matchers
22
22
  # expect(chef_run).to create_link('/tmp').with_link_type(:hard)
23
23
  #
24
- # @example Assert that a +link+ was createed with attributes
24
+ # @example Assert that a +link+ was created with attributes
25
25
  # expect(chef_run).to create_link('/tmp').with(link_type: :hard)
26
26
  #
27
- # @example Assert that a +link+ was createed using a regex
27
+ # @example Assert that a +link+ was created using a regex
28
28
  # expect(chef_run).to create_link('/tmp').with(link_type: Symbol)
29
29
  #
30
- # @example Assert that a +link+ was _not_ createed
30
+ # @example Assert that a +link+ was _not_ created
31
31
  # expect(chef_run).to_not create_link('/tmp')
32
32
  #
33
33
  #
@@ -52,19 +52,19 @@ module ChefSpec::API
52
52
  # The Examples section demonstrates the different ways to test a
53
53
  # +link+ resource with ChefSpec.
54
54
  #
55
- # @example Assert that a +link+ was deleteed
55
+ # @example Assert that a +link+ was deleted
56
56
  # expect(chef_run).to delete_link('/tmp')
57
57
  #
58
- # @example Assert that a +link+ was deleteed with predicate matchers
58
+ # @example Assert that a +link+ was deleted with predicate matchers
59
59
  # expect(chef_run).to delete_link('/tmp').with_link_type(:hard)
60
60
  #
61
- # @example Assert that a +link+ was deleteed with attributes
61
+ # @example Assert that a +link+ was deleted with attributes
62
62
  # expect(chef_run).to delete_link('/tmp').with(link_type: :hard)
63
63
  #
64
- # @example Assert that a +link+ was deleteed using a regex
64
+ # @example Assert that a +link+ was deleted using a regex
65
65
  # expect(chef_run).to delete_link('/tmp').with(link_type: Symbol)
66
66
  #
67
- # @example Assert that a +link+ was _not_ deleteed
67
+ # @example Assert that a +link+ was _not_ deleted
68
68
  # expect(chef_run).to_not delete_link('/tmp')
69
69
  #
70
70
  #
@@ -52,19 +52,19 @@ module ChefSpec::API
52
52
  # The Examples section demonstrates the different ways to test a
53
53
  # +mdadm+ resource with ChefSpec.
54
54
  #
55
- # @example Assert that a +mdadm+ was createed
55
+ # @example Assert that a +mdadm+ was created
56
56
  # expect(chef_run).to create_mdadm('/dev/md0')
57
57
  #
58
- # @example Assert that a +mdadm+ was createed with predicate matchers
58
+ # @example Assert that a +mdadm+ was created with predicate matchers
59
59
  # expect(chef_run).to create_mdadm('/dev/md0').with_devices(['/dev/sda'])
60
60
  #
61
- # @example Assert that a +mdadm+ was createed with attributes
61
+ # @example Assert that a +mdadm+ was created with attributes
62
62
  # expect(chef_run).to create_mdadm('/dev/md0').with(devices: ['/dev/sda'])
63
63
  #
64
- # @example Assert that a +mdadm+ was createed using a regex
64
+ # @example Assert that a +mdadm+ was created using a regex
65
65
  # expect(chef_run).to create_mdadm('/dev/md0').with(devices: '/dev/sda')
66
66
  #
67
- # @example Assert that a +mdadm+ was _not_ createed
67
+ # @example Assert that a +mdadm+ was _not_ created
68
68
  # expect(chef_run).to_not create_mdadm('/dev/md0')
69
69
  #
70
70
  #