chefspec 2.0.1 → 3.0.0.beta.1

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chefspec.rb +30 -44
  3. data/lib/chefspec/api.rb +74 -0
  4. data/lib/chefspec/api/apt_package.rb +192 -0
  5. data/lib/chefspec/api/batch.rb +43 -0
  6. data/lib/chefspec/api/chef_gem.rb +191 -0
  7. data/lib/chefspec/api/cookbook_file.rb +166 -0
  8. data/lib/chefspec/api/cron.rb +80 -0
  9. data/lib/chefspec/api/deploy.rb +117 -0
  10. data/lib/chefspec/api/directory.rb +80 -0
  11. data/lib/chefspec/api/dpkg_package.rb +117 -0
  12. data/lib/chefspec/api/easy_install_package.rb +154 -0
  13. data/lib/chefspec/api/env.rb +117 -0
  14. data/lib/chefspec/api/erl_call.rb +43 -0
  15. data/lib/chefspec/api/execute.rb +43 -0
  16. data/lib/chefspec/api/file.rb +166 -0
  17. data/lib/chefspec/api/freebsd_package.rb +80 -0
  18. data/lib/chefspec/api/gem_package.rb +191 -0
  19. data/lib/chefspec/api/git.rb +117 -0
  20. data/lib/chefspec/api/group.rb +154 -0
  21. data/lib/chefspec/api/http_request.rb +228 -0
  22. data/lib/chefspec/api/ifconfig.rb +154 -0
  23. data/lib/chefspec/api/include_recipe.rb +26 -0
  24. data/lib/chefspec/api/ips_package.rb +117 -0
  25. data/lib/chefspec/api/link.rb +102 -0
  26. data/lib/chefspec/api/log.rb +43 -0
  27. data/lib/chefspec/api/macports_package.rb +154 -0
  28. data/lib/chefspec/api/mdadm.rb +117 -0
  29. data/lib/chefspec/api/mount.rb +192 -0
  30. data/lib/chefspec/api/notifications.rb +38 -0
  31. data/lib/chefspec/api/ohai.rb +43 -0
  32. data/lib/chefspec/api/package.rb +192 -0
  33. data/lib/chefspec/api/pacman_package.rb +155 -0
  34. data/lib/chefspec/api/portage_package.rb +155 -0
  35. data/lib/chefspec/api/powershell_script.rb +43 -0
  36. data/lib/chefspec/api/registry_key.rb +166 -0
  37. data/lib/chefspec/api/remote_directory.rb +120 -0
  38. data/lib/chefspec/api/remote_file.rb +166 -0
  39. data/lib/chefspec/api/render_file.rb +32 -0
  40. data/lib/chefspec/api/route.rb +80 -0
  41. data/lib/chefspec/api/rpm_package.rb +117 -0
  42. data/lib/chefspec/api/ruby_block.rb +37 -0
  43. data/lib/chefspec/api/script.rb +228 -0
  44. data/lib/chefspec/api/service.rb +246 -0
  45. data/lib/chefspec/api/smartos_package.rb +117 -0
  46. data/lib/chefspec/api/solaris_package.rb +80 -0
  47. data/lib/chefspec/api/subversion.rb +154 -0
  48. data/lib/chefspec/api/template.rb +166 -0
  49. data/lib/chefspec/api/user.rb +228 -0
  50. data/lib/chefspec/api/yum_package.rb +154 -0
  51. data/lib/chefspec/berkshelf.rb +37 -0
  52. data/lib/chefspec/deprecations.rb +151 -0
  53. data/lib/chefspec/errors.rb +99 -0
  54. data/lib/chefspec/expect_exception.rb +45 -0
  55. data/lib/chefspec/extensions/chef/client.rb +15 -0
  56. data/lib/chefspec/extensions/chef/conditional.rb +11 -0
  57. data/lib/chefspec/extensions/chef/data_query.rb +29 -0
  58. data/lib/chefspec/extensions/chef/lwrp_base.rb +44 -0
  59. data/lib/chefspec/extensions/chef/resource.rb +27 -0
  60. data/lib/chefspec/extensions/chef/securable.rb +19 -0
  61. data/lib/chefspec/formatter.rb +270 -0
  62. data/lib/chefspec/macros.rb +217 -0
  63. data/lib/chefspec/matchers.rb +9 -0
  64. data/lib/chefspec/matchers/include_recipe_matcher.rb +45 -0
  65. data/lib/chefspec/matchers/link_to_matcher.rb +28 -0
  66. data/lib/chefspec/matchers/notifications_matcher.rb +92 -0
  67. data/lib/chefspec/matchers/render_file_matcher.rb +72 -0
  68. data/lib/chefspec/matchers/resource_matcher.rb +143 -0
  69. data/lib/chefspec/renderer.rb +137 -0
  70. data/lib/chefspec/rspec.rb +17 -0
  71. data/lib/chefspec/runner.rb +274 -0
  72. data/lib/chefspec/stubs/command_registry.rb +11 -0
  73. data/lib/chefspec/stubs/command_stub.rb +37 -0
  74. data/lib/chefspec/stubs/data_bag_item_registry.rb +13 -0
  75. data/lib/chefspec/stubs/data_bag_item_stub.rb +25 -0
  76. data/lib/chefspec/stubs/data_bag_registry.rb +13 -0
  77. data/lib/chefspec/stubs/data_bag_stub.rb +23 -0
  78. data/lib/chefspec/stubs/registry.rb +32 -0
  79. data/lib/chefspec/stubs/search_registry.rb +13 -0
  80. data/lib/chefspec/stubs/search_stub.rb +25 -0
  81. data/lib/chefspec/stubs/stub.rb +37 -0
  82. data/lib/chefspec/version.rb +1 -2
  83. metadata +100 -103
  84. data/lib/chef/expect_exception.rb +0 -34
  85. data/lib/chef/formatters/chefspec.rb +0 -233
  86. data/lib/chef/knife/cookbook_create_specs.rb +0 -107
  87. data/lib/chefspec/chef_runner.rb +0 -275
  88. data/lib/chefspec/helpers/describe.rb +0 -17
  89. data/lib/chefspec/matchers/cron.rb +0 -7
  90. data/lib/chefspec/matchers/env.rb +0 -8
  91. data/lib/chefspec/matchers/execute.rb +0 -33
  92. data/lib/chefspec/matchers/file.rb +0 -83
  93. data/lib/chefspec/matchers/file_content.rb +0 -32
  94. data/lib/chefspec/matchers/group.rb +0 -8
  95. data/lib/chefspec/matchers/include_recipe.rb +0 -20
  96. data/lib/chefspec/matchers/link.rb +0 -14
  97. data/lib/chefspec/matchers/log.rb +0 -21
  98. data/lib/chefspec/matchers/notifications.rb +0 -43
  99. data/lib/chefspec/matchers/package.rb +0 -39
  100. data/lib/chefspec/matchers/python.rb +0 -7
  101. data/lib/chefspec/matchers/ruby_block.rb +0 -13
  102. data/lib/chefspec/matchers/script.rb +0 -34
  103. data/lib/chefspec/matchers/service.rb +0 -25
  104. data/lib/chefspec/matchers/shared.rb +0 -132
  105. data/lib/chefspec/matchers/user.rb +0 -8
  106. data/lib/chefspec/minitest.rb +0 -195
  107. data/lib/chefspec/monkey_patches/conditional.rb +0 -19
  108. data/lib/chefspec/monkey_patches/hash.rb +0 -23
  109. data/lib/chefspec/monkey_patches/lwrp_base.rb +0 -45
  110. data/lib/chefspec/monkey_patches/provider.rb +0 -43
@@ -0,0 +1,102 @@
1
+ module ChefSpec::API
2
+ # @since 1.1.0
3
+ module LinkMatchers
4
+ ChefSpec::Runner.define_runner_method :link
5
+
6
+ #
7
+ # Assert that a +link+ resource exists in the Chef run with the
8
+ # action +:create+. Given a Chef Recipe that creates "/tmp" as a
9
+ # +link+:
10
+ #
11
+ # link '/tmp' do
12
+ # action :create
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +link+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +link+ was createed
19
+ # expect(chef_run).to create_link('/tmp')
20
+ #
21
+ # @example Assert that a +link+ was createed with predicate matchers
22
+ # expect(chef_run).to create_link('/tmp').with_link_type(:hard)
23
+ #
24
+ # @example Assert that a +link+ was createed with attributes
25
+ # expect(chef_run).to create_link('/tmp').with(link_type: :hard)
26
+ #
27
+ # @example Assert that a +link+ was createed using a regex
28
+ # expect(chef_run).to create_link('/tmp').with(link_type: Symbol)
29
+ #
30
+ # @example Assert that a +link+ was _not_ createed
31
+ # expect(chef_run).to_not create_link('/tmp')
32
+ #
33
+ #
34
+ # @param [String, Regex] resource_name
35
+ # the name of the resource to match
36
+ #
37
+ # @return [ChefSpec::Matchers::ResourceMatcher]
38
+ #
39
+ def create_link(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:link, :create, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that a +link+ resource exists in the Chef run with the
45
+ # action +:delete+. Given a Chef Recipe that deletes "/tmp" as a
46
+ # +link+:
47
+ #
48
+ # link '/tmp' do
49
+ # action :delete
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test a
53
+ # +link+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that a +link+ was deleteed
56
+ # expect(chef_run).to delete_link('/tmp')
57
+ #
58
+ # @example Assert that a +link+ was deleteed with predicate matchers
59
+ # expect(chef_run).to delete_link('/tmp').with_link_type(:hard)
60
+ #
61
+ # @example Assert that a +link+ was deleteed with attributes
62
+ # expect(chef_run).to delete_link('/tmp').with(link_type: :hard)
63
+ #
64
+ # @example Assert that a +link+ was deleteed using a regex
65
+ # expect(chef_run).to delete_link('/tmp').with(link_type: Symbol)
66
+ #
67
+ # @example Assert that a +link+ was _not_ deleteed
68
+ # expect(chef_run).to_not delete_link('/tmp')
69
+ #
70
+ #
71
+ # @param [String, Regex] resource_name
72
+ # the name of the resource to match
73
+ #
74
+ # @return [ChefSpec::Matchers::ResourceMatcher]
75
+ #
76
+ def delete_link(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:link, :delete, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that a symlink links to a specific path. This is really
82
+ # syntactic sugar for the following:
83
+ #
84
+ # expect(chef_run).to create_link('/tmp/thing').with(to: '/tmp/other_thing')
85
+ #
86
+ # @example Using +link_to+ with a String path
87
+ # link = chef_run.link('/tmp/thing')
88
+ # expect(link).to link_to('/tmp/other_thing')
89
+ #
90
+ # @example Using +link_to+ with a regular expression
91
+ # expect(link).to link_to(/\/tmp/(.+)/)
92
+ #
93
+ # @param [String, Regex] path
94
+ # the path to link to
95
+ #
96
+ # @return [ChefSpec::Matchers::LinkToMatcher]
97
+ #
98
+ def link_to(path)
99
+ ChefSpec::Matchers::LinkToMatcher.new(path)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,43 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module LogMatchers
4
+ ChefSpec::Runner.define_runner_method :log
5
+
6
+ #
7
+ # Assert that a +log+ resource exists in the Chef run with the
8
+ # action +:write+. Given a Chef Recipe that writes "message" as a
9
+ # +log+:
10
+ #
11
+ # log 'message' do
12
+ # action :write
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +log+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +log+ was writeed
19
+ # expect(chef_run).to write_log('message')
20
+ #
21
+ # @example Assert that a +log+ was writeed with predicate matchers
22
+ # expect(chef_run).to write_log('message').with_level(:info)
23
+ #
24
+ # @example Assert that a +log+ was writeed with attributes
25
+ # expect(chef_run).to write_log('message').with(level: :info)
26
+ #
27
+ # @example Assert that a +log+ was writeed using a regex
28
+ # expect(chef_run).to write_log('message').with(level: Symbol)
29
+ #
30
+ # @example Assert that a +log+ was _not_ writeed
31
+ # expect(chef_run).to_not write_log('message')
32
+ #
33
+ #
34
+ # @param [String, Regex] resource_name
35
+ # the name of the resource to match
36
+ #
37
+ # @return [ChefSpec::Matchers::ResourceMatcher]
38
+ #
39
+ def write_log(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:log, :write, resource_name)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,154 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module MacportsPackageMatchers
4
+ ChefSpec::Runner.define_runner_method :macports_package
5
+
6
+ #
7
+ # Assert that a +macports_package+ resource exists in the Chef run with the
8
+ # action +:install+. Given a Chef Recipe that installs "community-zero" as a
9
+ # +macports_package+:
10
+ #
11
+ # macports_package 'community-zero' do
12
+ # action :install
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +macports_package+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +macports_package+ was installed
19
+ # expect(chef_run).to install_macports_package('community-zero')
20
+ #
21
+ # @example Assert that a +macports_package+ was installed with predicate matchers
22
+ # expect(chef_run).to install_macports_package('community-zero').with_version('1.2.3')
23
+ #
24
+ # @example Assert that a +macports_package+ was installed with attributes
25
+ # expect(chef_run).to install_macports_package('community-zero').with(version: '1.2.3')
26
+ #
27
+ # @example Assert that a +macports_package+ was installed using a regex
28
+ # expect(chef_run).to install_macports_package('community-zero').with(version: /(\d+\.){2}\.\d+/)
29
+ #
30
+ # @example Assert that a +macports_package+ was _not_ installed
31
+ # expect(chef_run).to_not install_macports_package('community-zero')
32
+ #
33
+ #
34
+ # @param [String, Regex] resource_name
35
+ # the name of the resource to match
36
+ #
37
+ # @return [ChefSpec::Matchers::ResourceMatcher]
38
+ #
39
+ def install_macports_package(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:macports_package, :install, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that a +macports_package+ resource exists in the Chef run with the
45
+ # action +:purge+. Given a Chef Recipe that purges "community-zero" as a
46
+ # +macports_package+:
47
+ #
48
+ # macports_package 'community-zero' do
49
+ # action :purge
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test a
53
+ # +macports_package+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that a +macports_package+ was purgeed
56
+ # expect(chef_run).to purge_macports_package('community-zero')
57
+ #
58
+ # @example Assert that a +macports_package+ was purgeed with predicate matchers
59
+ # expect(chef_run).to purge_macports_package('community-zero').with_version('1.2.3')
60
+ #
61
+ # @example Assert that a +macports_package+ was purgeed with attributes
62
+ # expect(chef_run).to purge_macports_package('community-zero').with(version: '1.2.3')
63
+ #
64
+ # @example Assert that a +macports_package+ was purgeed using a regex
65
+ # expect(chef_run).to purge_macports_package('community-zero').with(version: /(\d+\.){2}\.\d+/)
66
+ #
67
+ # @example Assert that a +macports_package+ was _not_ purgeed
68
+ # expect(chef_run).to_not purge_macports_package('community-zero')
69
+ #
70
+ #
71
+ # @param [String, Regex] resource_name
72
+ # the name of the resource to match
73
+ #
74
+ # @return [ChefSpec::Matchers::ResourceMatcher]
75
+ #
76
+ def purge_macports_package(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:macports_package, :purge, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that a +macports_package+ resource exists in the Chef run with the
82
+ # action +:remove+. Given a Chef Recipe that removes "community-zero" as a
83
+ # +macports_package+:
84
+ #
85
+ # macports_package 'community-zero' do
86
+ # action :remove
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test a
90
+ # +macports_package+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that a +macports_package+ was removeed
93
+ # expect(chef_run).to remove_macports_package('community-zero')
94
+ #
95
+ # @example Assert that a +macports_package+ was removeed with predicate matchers
96
+ # expect(chef_run).to remove_macports_package('community-zero').with_version('1.2.3')
97
+ #
98
+ # @example Assert that a +macports_package+ was removeed with attributes
99
+ # expect(chef_run).to remove_macports_package('community-zero').with(version: '1.2.3')
100
+ #
101
+ # @example Assert that a +macports_package+ was removeed using a regex
102
+ # expect(chef_run).to remove_macports_package('community-zero').with(version: /(\d+\.){2}\.\d+/)
103
+ #
104
+ # @example Assert that a +macports_package+ was _not_ removeed
105
+ # expect(chef_run).to_not remove_macports_package('community-zero')
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 remove_macports_package(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:macports_package, :remove, resource_name)
115
+ end
116
+
117
+ #
118
+ # Assert that a +macports_package+ resource exists in the Chef run with the
119
+ # action +:upgrade+. Given a Chef Recipe that upgrades "community-zero" as a
120
+ # +macports_package+:
121
+ #
122
+ # macports_package 'community-zero' do
123
+ # action :upgrade
124
+ # end
125
+ #
126
+ # The Examples section demonstrates the different ways to test a
127
+ # +macports_package+ resource with ChefSpec.
128
+ #
129
+ # @example Assert that a +macports_package+ was upgradeed
130
+ # expect(chef_run).to upgrade_macports_package('community-zero')
131
+ #
132
+ # @example Assert that a +macports_package+ was upgradeed with predicate matchers
133
+ # expect(chef_run).to upgrade_macports_package('community-zero').with_version('1.2.3')
134
+ #
135
+ # @example Assert that a +macports_package+ was upgradeed with attributes
136
+ # expect(chef_run).to upgrade_macports_package('community-zero').with(version: '1.2.3')
137
+ #
138
+ # @example Assert that a +macports_package+ was upgradeed using a regex
139
+ # expect(chef_run).to upgrade_macports_package('community-zero').with(version: /(\d+\.){2}\.\d+/)
140
+ #
141
+ # @example Assert that a +macports_package+ was _not_ upgradeed
142
+ # expect(chef_run).to_not upgrade_macports_package('community-zero')
143
+ #
144
+ #
145
+ # @param [String, Regex] resource_name
146
+ # the name of the resource to match
147
+ #
148
+ # @return [ChefSpec::Matchers::ResourceMatcher]
149
+ #
150
+ def upgrade_macports_package(resource_name)
151
+ ChefSpec::Matchers::ResourceMatcher.new(:macports_package, :upgrade, resource_name)
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,117 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module MdadmMatchers
4
+ ChefSpec::Runner.define_runner_method :mdadm
5
+
6
+ #
7
+ # Assert that a +mdadm+ resource exists in the Chef run with the
8
+ # action +:assemble+. Given a Chef Recipe that assembles "/dev/md0" as a
9
+ # +mdadm+:
10
+ #
11
+ # mdadm '/dev/md0' do
12
+ # action :assemble
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +mdadm+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +mdadm+ was assembled
19
+ # expect(chef_run).to assemble_mdadm('/dev/md0')
20
+ #
21
+ # @example Assert that a +mdadm+ was assembled with predicate matchers
22
+ # expect(chef_run).to assemble_mdadm('/dev/md0').with_devices(['/dev/sda'])
23
+ #
24
+ # @example Assert that a +mdadm+ was assembled with attributes
25
+ # expect(chef_run).to assemble_mdadm('/dev/md0').with(devices: ['/dev/sda'])
26
+ #
27
+ # @example Assert that a +mdadm+ was assembled using a regex
28
+ # expect(chef_run).to assemble_mdadm('/dev/md0').with(devices: '/dev/sda')
29
+ #
30
+ # @example Assert that a +mdadm+ was _not_ assembled
31
+ # expect(chef_run).to_not assemble_mdadm('/dev/md0')
32
+ #
33
+ #
34
+ # @param [String, Regex] resource_name
35
+ # the name of the resource to match
36
+ #
37
+ # @return [ChefSpec::Matchers::ResourceMatcher]
38
+ #
39
+ def assemble_mdadm(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :assemble, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that a +mdadm+ resource exists in the Chef run with the
45
+ # action +:create+. Given a Chef Recipe that creates "/dev/md0" as a
46
+ # +mdadm+:
47
+ #
48
+ # mdadm '/dev/md0' do
49
+ # action :create
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test a
53
+ # +mdadm+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that a +mdadm+ was createed
56
+ # expect(chef_run).to create_mdadm('/dev/md0')
57
+ #
58
+ # @example Assert that a +mdadm+ was createed with predicate matchers
59
+ # expect(chef_run).to create_mdadm('/dev/md0').with_devices(['/dev/sda'])
60
+ #
61
+ # @example Assert that a +mdadm+ was createed with attributes
62
+ # expect(chef_run).to create_mdadm('/dev/md0').with(devices: ['/dev/sda'])
63
+ #
64
+ # @example Assert that a +mdadm+ was createed using a regex
65
+ # expect(chef_run).to create_mdadm('/dev/md0').with(devices: '/dev/sda')
66
+ #
67
+ # @example Assert that a +mdadm+ was _not_ createed
68
+ # expect(chef_run).to_not create_mdadm('/dev/md0')
69
+ #
70
+ #
71
+ # @param [String, Regex] resource_name
72
+ # the name of the resource to match
73
+ #
74
+ # @return [ChefSpec::Matchers::ResourceMatcher]
75
+ #
76
+ def create_mdadm(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :create, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that a +mdadm+ resource exists in the Chef run with the
82
+ # action +:stop+. Given a Chef Recipe that stops "/dev/md0" as a
83
+ # +mdadm+:
84
+ #
85
+ # mdadm '/dev/md0' do
86
+ # action :stop
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test a
90
+ # +mdadm+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that a +mdadm+ was stopped
93
+ # expect(chef_run).to stop_mdadm('/dev/md0')
94
+ #
95
+ # @example Assert that a +mdadm+ was stopped with predicate matchers
96
+ # expect(chef_run).to stop_mdadm('/dev/md0').with_devices(['/dev/sda'])
97
+ #
98
+ # @example Assert that a +mdadm+ was stopped with attributes
99
+ # expect(chef_run).to stop_mdadm('/dev/md0').with(devices: ['/dev/sda'])
100
+ #
101
+ # @example Assert that a +mdadm+ was stopped using a regex
102
+ # expect(chef_run).to stop_mdadm('/dev/md0').with(devices: '/dev/sda')
103
+ #
104
+ # @example Assert that a +mdadm+ was _not_ stopped
105
+ # expect(chef_run).to_not stop_mdadm('/dev/md0')
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 stop_mdadm(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:mdadm, :stop, resource_name)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,192 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module MountMatchers
4
+ ChefSpec::Runner.define_runner_method :mount
5
+
6
+ #
7
+ # Assert that a +mount+ resource exists in the Chef run with the
8
+ # action +:disable+. Given a Chef Recipe that disables "/mnt/volume1" as a
9
+ # +mount+:
10
+ #
11
+ # mount '/mnt/volume1' do
12
+ # action :disable
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +mount+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that a +mount+ was disableed
19
+ # expect(chef_run).to disable_mount('/mnt/volume1')
20
+ #
21
+ # @example Assert that a +mount+ was disableed with predicate matchers
22
+ # expect(chef_run).to disable_mount('/mnt/volume1').with_pass(4)
23
+ #
24
+ # @example Assert that a +mount+ was disableed with attributes
25
+ # expect(chef_run).to disable_mount('/mnt/volume1').with(pass: 4)
26
+ #
27
+ # @example Assert that a +mount+ was disableed using a regex
28
+ # expect(chef_run).to disable_mount('/mnt/volume1').with(pass: /\d+/)
29
+ #
30
+ # @example Assert that a +mount+ was _not_ disableed
31
+ # expect(chef_run).to_not disable_mount('/mnt/volume1')
32
+ #
33
+ #
34
+ # @param [String, Regex] resource_name
35
+ # the name of the resource to match
36
+ #
37
+ # @return [ChefSpec::Matchers::ResourceMatcher]
38
+ #
39
+ def disable_mount(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:mount, :disable, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that a +mount+ resource exists in the Chef run with the
45
+ # action +:enable+. Given a Chef Recipe that enables "/mnt/volume1" as a
46
+ # +mount+:
47
+ #
48
+ # mount '/mnt/volume1' do
49
+ # action :enable
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test a
53
+ # +mount+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that a +mount+ was enabled
56
+ # expect(chef_run).to enable_mount('/mnt/volume1')
57
+ #
58
+ # @example Assert that a +mount+ was enabled with predicate matchers
59
+ # expect(chef_run).to enable_mount('/mnt/volume1').with_pass(4)
60
+ #
61
+ # @example Assert that a +mount+ was enabled with attributes
62
+ # expect(chef_run).to enable_mount('/mnt/volume1').with(pass: 4)
63
+ #
64
+ # @example Assert that a +mount+ was enabled using a regex
65
+ # expect(chef_run).to enable_mount('/mnt/volume1').with(pass: /\d+/)
66
+ #
67
+ # @example Assert that a +mount+ was _not_ enabled
68
+ # expect(chef_run).to_not enable_mount('/mnt/volume1')
69
+ #
70
+ #
71
+ # @param [String, Regex] resource_name
72
+ # the name of the resource to match
73
+ #
74
+ # @return [ChefSpec::Matchers::ResourceMatcher]
75
+ #
76
+ def enable_mount(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:mount, :enable, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that a +mount+ resource exists in the Chef run with the
82
+ # action +:mount+. Given a Chef Recipe that mounts "/mnt/volume1" as a
83
+ # +mount+:
84
+ #
85
+ # mount '/mnt/volume1' do
86
+ # action :mount
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test a
90
+ # +mount+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that a +mount+ was mounted
93
+ # expect(chef_run).to mount_mount('/mnt/volume1')
94
+ #
95
+ # @example Assert that a +mount+ was mounted with predicate matchers
96
+ # expect(chef_run).to mount_mount('/mnt/volume1').with_pass(4)
97
+ #
98
+ # @example Assert that a +mount+ was mounted with attributes
99
+ # expect(chef_run).to mount_mount('/mnt/volume1').with(pass: 4)
100
+ #
101
+ # @example Assert that a +mount+ was mounted using a regex
102
+ # expect(chef_run).to mount_mount('/mnt/volume1').with(pass: /\d+/)
103
+ #
104
+ # @example Assert that a +mount+ was _not_ mounted
105
+ # expect(chef_run).to_not mount_mount('/mnt/volume1')
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 mount_mount(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:mount, :mount, resource_name)
115
+ end
116
+
117
+ #
118
+ # Assert that a +mount+ resource exists in the Chef run with the
119
+ # action +:remount+. Given a Chef Recipe that remounts "/mnt/volume1" as a
120
+ # +mount+:
121
+ #
122
+ # mount '/mnt/volume1' do
123
+ # action :remount
124
+ # end
125
+ #
126
+ # The Examples section demonstrates the different ways to test a
127
+ # +mount+ resource with ChefSpec.
128
+ #
129
+ # @example Assert that a +mount+ was remounted
130
+ # expect(chef_run).to remount_mount('/mnt/volume1')
131
+ #
132
+ # @example Assert that a +mount+ was remounted with predicate matchers
133
+ # expect(chef_run).to remount_mount('/mnt/volume1').with_pass(4)
134
+ #
135
+ # @example Assert that a +mount+ was remounted with attributes
136
+ # expect(chef_run).to remount_mount('/mnt/volume1').with(pass: 4)
137
+ #
138
+ # @example Assert that a +mount+ was remounted using a regex
139
+ # expect(chef_run).to remount_mount('/mnt/volume1').with(pass: /\d+/)
140
+ #
141
+ # @example Assert that a +mount+ was _not_ remounted
142
+ # expect(chef_run).to_not remount_mount('/mnt/volume1')
143
+ #
144
+ #
145
+ # @param [String, Regex] resource_name
146
+ # the name of the resource to match
147
+ #
148
+ # @return [ChefSpec::Matchers::ResourceMatcher]
149
+ #
150
+ def remount_mount(resource_name)
151
+ ChefSpec::Matchers::ResourceMatcher.new(:mount, :remount, resource_name)
152
+ end
153
+
154
+ #
155
+ # Assert that a +mount+ resource exists in the Chef run with the
156
+ # action +:umount+. Given a Chef Recipe that umounts "/mnt/volume1" as a
157
+ # +mount+:
158
+ #
159
+ # mount '/mnt/volume1' do
160
+ # action :umount
161
+ # end
162
+ #
163
+ # The Examples section demonstrates the different ways to test a
164
+ # +mount+ resource with ChefSpec.
165
+ #
166
+ # @example Assert that a +mount+ was umounted
167
+ # expect(chef_run).to umount_mount('/mnt/volume1')
168
+ #
169
+ # @example Assert that a +mount+ was umounted with predicate matchers
170
+ # expect(chef_run).to umount_mount('/mnt/volume1').with_pass(4)
171
+ #
172
+ # @example Assert that a +mount+ was umounted with attributes
173
+ # expect(chef_run).to umount_mount('/mnt/volume1').with(pass: 4)
174
+ #
175
+ # @example Assert that a +mount+ was umounted using a regex
176
+ # expect(chef_run).to umount_mount('/mnt/volume1').with(pass: /\d+/)
177
+ #
178
+ # @example Assert that a +mount+ was _not_ umounted
179
+ # expect(chef_run).to_not umount_mount('/mnt/volume1')
180
+ #
181
+ #
182
+ # @param [String, Regex] resource_name
183
+ # the name of the resource to match
184
+ #
185
+ # @return [ChefSpec::Matchers::ResourceMatcher]
186
+ #
187
+ def umount_mount(resource_name)
188
+ ChefSpec::Matchers::ResourceMatcher.new(:mount, :umount, resource_name)
189
+ end
190
+
191
+ end
192
+ end