chefspec 2.0.1 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chefspec.rb +30 -44
- data/lib/chefspec/api.rb +74 -0
- data/lib/chefspec/api/apt_package.rb +192 -0
- data/lib/chefspec/api/batch.rb +43 -0
- data/lib/chefspec/api/chef_gem.rb +191 -0
- data/lib/chefspec/api/cookbook_file.rb +166 -0
- data/lib/chefspec/api/cron.rb +80 -0
- data/lib/chefspec/api/deploy.rb +117 -0
- data/lib/chefspec/api/directory.rb +80 -0
- data/lib/chefspec/api/dpkg_package.rb +117 -0
- data/lib/chefspec/api/easy_install_package.rb +154 -0
- data/lib/chefspec/api/env.rb +117 -0
- data/lib/chefspec/api/erl_call.rb +43 -0
- data/lib/chefspec/api/execute.rb +43 -0
- data/lib/chefspec/api/file.rb +166 -0
- data/lib/chefspec/api/freebsd_package.rb +80 -0
- data/lib/chefspec/api/gem_package.rb +191 -0
- data/lib/chefspec/api/git.rb +117 -0
- data/lib/chefspec/api/group.rb +154 -0
- data/lib/chefspec/api/http_request.rb +228 -0
- data/lib/chefspec/api/ifconfig.rb +154 -0
- data/lib/chefspec/api/include_recipe.rb +26 -0
- data/lib/chefspec/api/ips_package.rb +117 -0
- data/lib/chefspec/api/link.rb +102 -0
- data/lib/chefspec/api/log.rb +43 -0
- data/lib/chefspec/api/macports_package.rb +154 -0
- data/lib/chefspec/api/mdadm.rb +117 -0
- data/lib/chefspec/api/mount.rb +192 -0
- data/lib/chefspec/api/notifications.rb +38 -0
- data/lib/chefspec/api/ohai.rb +43 -0
- data/lib/chefspec/api/package.rb +192 -0
- data/lib/chefspec/api/pacman_package.rb +155 -0
- data/lib/chefspec/api/portage_package.rb +155 -0
- data/lib/chefspec/api/powershell_script.rb +43 -0
- data/lib/chefspec/api/registry_key.rb +166 -0
- data/lib/chefspec/api/remote_directory.rb +120 -0
- data/lib/chefspec/api/remote_file.rb +166 -0
- data/lib/chefspec/api/render_file.rb +32 -0
- data/lib/chefspec/api/route.rb +80 -0
- data/lib/chefspec/api/rpm_package.rb +117 -0
- data/lib/chefspec/api/ruby_block.rb +37 -0
- data/lib/chefspec/api/script.rb +228 -0
- data/lib/chefspec/api/service.rb +246 -0
- data/lib/chefspec/api/smartos_package.rb +117 -0
- data/lib/chefspec/api/solaris_package.rb +80 -0
- data/lib/chefspec/api/subversion.rb +154 -0
- data/lib/chefspec/api/template.rb +166 -0
- data/lib/chefspec/api/user.rb +228 -0
- data/lib/chefspec/api/yum_package.rb +154 -0
- data/lib/chefspec/berkshelf.rb +37 -0
- data/lib/chefspec/deprecations.rb +151 -0
- data/lib/chefspec/errors.rb +99 -0
- data/lib/chefspec/expect_exception.rb +45 -0
- data/lib/chefspec/extensions/chef/client.rb +15 -0
- data/lib/chefspec/extensions/chef/conditional.rb +11 -0
- data/lib/chefspec/extensions/chef/data_query.rb +29 -0
- data/lib/chefspec/extensions/chef/lwrp_base.rb +44 -0
- data/lib/chefspec/extensions/chef/resource.rb +27 -0
- data/lib/chefspec/extensions/chef/securable.rb +19 -0
- data/lib/chefspec/formatter.rb +270 -0
- data/lib/chefspec/macros.rb +217 -0
- data/lib/chefspec/matchers.rb +9 -0
- data/lib/chefspec/matchers/include_recipe_matcher.rb +45 -0
- data/lib/chefspec/matchers/link_to_matcher.rb +28 -0
- data/lib/chefspec/matchers/notifications_matcher.rb +92 -0
- data/lib/chefspec/matchers/render_file_matcher.rb +72 -0
- data/lib/chefspec/matchers/resource_matcher.rb +143 -0
- data/lib/chefspec/renderer.rb +137 -0
- data/lib/chefspec/rspec.rb +17 -0
- data/lib/chefspec/runner.rb +274 -0
- data/lib/chefspec/stubs/command_registry.rb +11 -0
- data/lib/chefspec/stubs/command_stub.rb +37 -0
- data/lib/chefspec/stubs/data_bag_item_registry.rb +13 -0
- data/lib/chefspec/stubs/data_bag_item_stub.rb +25 -0
- data/lib/chefspec/stubs/data_bag_registry.rb +13 -0
- data/lib/chefspec/stubs/data_bag_stub.rb +23 -0
- data/lib/chefspec/stubs/registry.rb +32 -0
- data/lib/chefspec/stubs/search_registry.rb +13 -0
- data/lib/chefspec/stubs/search_stub.rb +25 -0
- data/lib/chefspec/stubs/stub.rb +37 -0
- data/lib/chefspec/version.rb +1 -2
- metadata +100 -103
- data/lib/chef/expect_exception.rb +0 -34
- data/lib/chef/formatters/chefspec.rb +0 -233
- data/lib/chef/knife/cookbook_create_specs.rb +0 -107
- data/lib/chefspec/chef_runner.rb +0 -275
- data/lib/chefspec/helpers/describe.rb +0 -17
- data/lib/chefspec/matchers/cron.rb +0 -7
- data/lib/chefspec/matchers/env.rb +0 -8
- data/lib/chefspec/matchers/execute.rb +0 -33
- data/lib/chefspec/matchers/file.rb +0 -83
- data/lib/chefspec/matchers/file_content.rb +0 -32
- data/lib/chefspec/matchers/group.rb +0 -8
- data/lib/chefspec/matchers/include_recipe.rb +0 -20
- data/lib/chefspec/matchers/link.rb +0 -14
- data/lib/chefspec/matchers/log.rb +0 -21
- data/lib/chefspec/matchers/notifications.rb +0 -43
- data/lib/chefspec/matchers/package.rb +0 -39
- data/lib/chefspec/matchers/python.rb +0 -7
- data/lib/chefspec/matchers/ruby_block.rb +0 -13
- data/lib/chefspec/matchers/script.rb +0 -34
- data/lib/chefspec/matchers/service.rb +0 -25
- data/lib/chefspec/matchers/shared.rb +0 -132
- data/lib/chefspec/matchers/user.rb +0 -8
- data/lib/chefspec/minitest.rb +0 -195
- data/lib/chefspec/monkey_patches/conditional.rb +0 -19
- data/lib/chefspec/monkey_patches/hash.rb +0 -23
- data/lib/chefspec/monkey_patches/lwrp_base.rb +0 -45
- data/lib/chefspec/monkey_patches/provider.rb +0 -43
@@ -0,0 +1,43 @@
|
|
1
|
+
module ChefSpec::API
|
2
|
+
# @since 3.0.0
|
3
|
+
module PowershellScriptMatchers
|
4
|
+
ChefSpec::Runner.define_runner_method :powershell_script
|
5
|
+
|
6
|
+
#
|
7
|
+
# Assert that a +powershell_script+ resource exists in the Chef run with the
|
8
|
+
# action +:run+. Given a Chef Recipe that runs "/tmp" as a
|
9
|
+
# +powershell_script+:
|
10
|
+
#
|
11
|
+
# powershell_script '/tmp' do
|
12
|
+
# action :run
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# The Examples section demonstrates the different ways to test a
|
16
|
+
# +powershell_script+ resource with ChefSpec.
|
17
|
+
#
|
18
|
+
# @example Assert that a +powershell_script+ was runed
|
19
|
+
# expect(chef_run).to run_powershell_script('/tmp')
|
20
|
+
#
|
21
|
+
# @example Assert that a +powershell_script+ was runed with predicate matchers
|
22
|
+
# expect(chef_run).to run_powershell_script('/tmp').with_user('svargo')
|
23
|
+
#
|
24
|
+
# @example Assert that a +powershell_script+ was runed with attributes
|
25
|
+
# expect(chef_run).to run_powershell_script('/tmp').with(user: 'svargo')
|
26
|
+
#
|
27
|
+
# @example Assert that a +powershell_script+ was runed using a regex
|
28
|
+
# expect(chef_run).to run_powershell_script('/tmp').with(user: /sva(.+)/)
|
29
|
+
#
|
30
|
+
# @example Assert that a +powershell_script+ was _not_ runed
|
31
|
+
# expect(chef_run).to_not run_powershell_script('/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 run_powershell_script(resource_name)
|
40
|
+
ChefSpec::Matchers::ResourceMatcher.new(:powershell_script, :run, resource_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module ChefSpec::API
|
2
|
+
# @since 3.0.0
|
3
|
+
module RegistryKeyMatchers
|
4
|
+
ChefSpec::Runner.define_runner_method :registry_key
|
5
|
+
|
6
|
+
#
|
7
|
+
# Assert that a +registry_key+ resource exists in the Chef run with the
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "HKEY_LOCAL_MACHINE\\SOFTWARE" as a
|
9
|
+
# +registry_key+:
|
10
|
+
#
|
11
|
+
# registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
|
12
|
+
# action :create
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# To test the content rendered by a +registry_key+, see
|
16
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
17
|
+
#
|
18
|
+
# The Examples section demonstrates the different ways to test a
|
19
|
+
# +registry_key+ resource with ChefSpec.
|
20
|
+
#
|
21
|
+
# @example Assert that a +registry_key+ was created
|
22
|
+
# expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
23
|
+
#
|
24
|
+
# @example Assert that a +registry_key+ was created with predicate matchers
|
25
|
+
# expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)
|
26
|
+
#
|
27
|
+
# @example Assert that a +registry_key+ was created with attributes
|
28
|
+
# expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)
|
29
|
+
#
|
30
|
+
# @example Assert that a +registry_key+ was created using a regex
|
31
|
+
# expect(chef_run).to create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)
|
32
|
+
#
|
33
|
+
# @example Assert that a +registry_key+ was _not_ created
|
34
|
+
# expect(chef_run).to_not create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
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 create_registry_key(resource_name)
|
43
|
+
ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :create, resource_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Assert that a +registry_key+ resource exists in the Chef run with the
|
48
|
+
# action +:create_if_missing+. Given a Chef Recipe that creates "HKEY_LOCAL_MACHINE\\SOFTWARE"
|
49
|
+
# if missing as a +registry_key+:
|
50
|
+
#
|
51
|
+
# registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
|
52
|
+
# action :create_if_missing
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# To test the content rendered by a +registry_key+, see
|
56
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
57
|
+
#
|
58
|
+
# The Examples section demonstrates the different ways to test a
|
59
|
+
# +registry_key+ resource with ChefSpec.
|
60
|
+
#
|
61
|
+
# @example Assert that a +registry_key+ was created if missing
|
62
|
+
# expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
63
|
+
#
|
64
|
+
# @example Assert that a +registry_key+ was created if missing with predicate matchers
|
65
|
+
# expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)
|
66
|
+
#
|
67
|
+
# @example Assert that a +registry_key+ was created if missing with attributes
|
68
|
+
# expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)
|
69
|
+
#
|
70
|
+
# @example Assert that a +registry_key+ was created if missing using a regex
|
71
|
+
# expect(chef_run).to create_registry_key_if_missing('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)
|
72
|
+
#
|
73
|
+
# @example Assert that a +registry_key+ was _not_ created if missing
|
74
|
+
# expect(chef_run).to_not create_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
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 create_registry_key_if_missing(resource_name)
|
83
|
+
ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :create_if_missing, resource_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Assert that a +registry_key+ resource exists in the Chef run with the
|
88
|
+
# action +:delete+. Given a Chef Recipe that deletes "HKEY_LOCAL_MACHINE\\SOFTWARE" as a
|
89
|
+
# +registry_key+:
|
90
|
+
#
|
91
|
+
# registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
|
92
|
+
# action :delete
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# To test the content rendered by a +registry_key+, see
|
96
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
97
|
+
#
|
98
|
+
# The Examples section demonstrates the different ways to test a
|
99
|
+
# +registry_key+ resource with ChefSpec.
|
100
|
+
#
|
101
|
+
# @example Assert that a +registry_key+ was deleted
|
102
|
+
# expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
103
|
+
#
|
104
|
+
# @example Assert that a +registry_key+ was deleted with predicate matchers
|
105
|
+
# expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)
|
106
|
+
#
|
107
|
+
# @example Assert that a +registry_key+ was deleted with attributes
|
108
|
+
# expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)
|
109
|
+
#
|
110
|
+
# @example Assert that a +registry_key+ was deleted using a regex
|
111
|
+
# expect(chef_run).to delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)
|
112
|
+
#
|
113
|
+
# @example Assert that a +registry_key+ was _not_ deleted
|
114
|
+
# expect(chef_run).to_not delete_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
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 delete_registry_key(resource_name)
|
123
|
+
ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :delete, resource_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Assert that a +registry_key+ resource exists in the Chef run with the
|
128
|
+
# action +:delete_key+. Given a Chef Recipe that delete_keys "HKEY_LOCAL_MACHINE\\SOFTWARE" as a
|
129
|
+
# +registry_key+:
|
130
|
+
#
|
131
|
+
# registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE' do
|
132
|
+
# action :delete_key
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# To test the content rendered by a +registry_key+, see
|
136
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
137
|
+
#
|
138
|
+
# The Examples section demonstrates the different ways to test a
|
139
|
+
# +registry_key+ resource with ChefSpec.
|
140
|
+
#
|
141
|
+
# @example Assert that a +registry_key+ was delete_keyd
|
142
|
+
# expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
143
|
+
#
|
144
|
+
# @example Assert that a +registry_key+ was delete_keyd with predicate matchers
|
145
|
+
# expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with_recursive(false)
|
146
|
+
#
|
147
|
+
# @example Assert that a +registry_key+ was delete_keyd with attributes
|
148
|
+
# expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(recursive: false)
|
149
|
+
#
|
150
|
+
# @example Assert that a +registry_key+ was delete_keyd using a regex
|
151
|
+
# expect(chef_run).to delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE').with(values: Array)
|
152
|
+
#
|
153
|
+
# @example Assert that a +registry_key+ was _not_ delete_keyd
|
154
|
+
# expect(chef_run).to_not delete_key_registry_key('HKEY_LOCAL_MACHINE\\SOFTWARE')
|
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 delete_key_registry_key(resource_name)
|
163
|
+
ChefSpec::Matchers::ResourceMatcher.new(:registry_key, :delete_key, resource_name)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module ChefSpec::API
|
2
|
+
# @since 3.0.0
|
3
|
+
module RemoteDirectoryMatchers
|
4
|
+
ChefSpec::Runner.define_runner_method :remote_directory
|
5
|
+
|
6
|
+
#
|
7
|
+
# Assert that a +remote_directory+ resource exists in the Chef run with the
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "/tmp" as a
|
9
|
+
# +remote_directory+:
|
10
|
+
#
|
11
|
+
# remote_directory '/tmp' do
|
12
|
+
# action :create
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# The Examples section demonstrates the different ways to test a
|
16
|
+
# +remote_directory+ resource with ChefSpec.
|
17
|
+
#
|
18
|
+
# @example Assert that a +remote_directory+ was createed
|
19
|
+
# expect(chef_run).to create_remote_directory('/tmp')
|
20
|
+
#
|
21
|
+
# @example Assert that a +remote_directory+ was createed with predicate matchers
|
22
|
+
# expect(chef_run).to create_remote_directory('/tmp').with_overwrite(true)
|
23
|
+
#
|
24
|
+
# @example Assert that a +remote_directory+ was createed with attributes
|
25
|
+
# expect(chef_run).to create_remote_directory('/tmp').with(overwrite: true)
|
26
|
+
#
|
27
|
+
# @example Assert that a +remote_directory+ was createed using a regex
|
28
|
+
# expect(chef_run).to create_remote_directory('/tmp').with(overwrite: Boolean)
|
29
|
+
#
|
30
|
+
# @example Assert that a +remote_directory+ was _not_ createed
|
31
|
+
# expect(chef_run).to_not create_remote_directory('/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_remote_directory(resource_name)
|
40
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :create, resource_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Assert that a +remote_directory+ resource exists in the Chef run with the
|
45
|
+
# action +:create_if_missing+. Given a Chef Recipe that creates "/tmp/config"
|
46
|
+
# if missing as a +remote_directory+:
|
47
|
+
#
|
48
|
+
# remote_directory '/tmp/config' do
|
49
|
+
# action :create_if_missing
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# To test the content rendered by a +remote_directory+, see
|
53
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
54
|
+
#
|
55
|
+
# The Examples section demonstrates the different ways to test a
|
56
|
+
# +remote_directory+ resource with ChefSpec.
|
57
|
+
#
|
58
|
+
# @example Assert that a +remote_directory+ was created if missing
|
59
|
+
# expect(chef_run).to create_remote_directory_if_missing('/tmp/config')
|
60
|
+
#
|
61
|
+
# @example Assert that a +remote_directory+ was created if missing with predicate matchers
|
62
|
+
# expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with_overwrite(true)
|
63
|
+
#
|
64
|
+
# @example Assert that a +remote_directory+ was created if missing with attributes
|
65
|
+
# expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with(overwrite: true)
|
66
|
+
#
|
67
|
+
# @example Assert that a +remote_directory+ was created if missing using a regex
|
68
|
+
# expect(chef_run).to create_remote_directory_if_missing('/tmp/config').with(overwrite: Boolean)
|
69
|
+
#
|
70
|
+
# @example Assert that a +remote_directory+ was _not_ created if missing
|
71
|
+
# expect(chef_run).to_not create_remote_directory('/tmp/config')
|
72
|
+
#
|
73
|
+
#
|
74
|
+
# @param [String, Regex] resource_name
|
75
|
+
# the name of the resource to match
|
76
|
+
#
|
77
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
78
|
+
#
|
79
|
+
def create_remote_directory_if_missing(resource_name)
|
80
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :create_if_missing, resource_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Assert that a +remote_directory+ resource exists in the Chef run with the
|
85
|
+
# action +:delete+. Given a Chef Recipe that deletes "/tmp" as a
|
86
|
+
# +remote_directory+:
|
87
|
+
#
|
88
|
+
# remote_directory '/tmp' do
|
89
|
+
# action :delete
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# The Examples section demonstrates the different ways to test a
|
93
|
+
# +remote_directory+ resource with ChefSpec.
|
94
|
+
#
|
95
|
+
# @example Assert that a +remote_directory+ was deleteed
|
96
|
+
# expect(chef_run).to delete_remote_directory('/tmp')
|
97
|
+
#
|
98
|
+
# @example Assert that a +remote_directory+ was deleteed with predicate matchers
|
99
|
+
# expect(chef_run).to delete_remote_directory('/tmp').with_overwrite(true)
|
100
|
+
#
|
101
|
+
# @example Assert that a +remote_directory+ was deleteed with attributes
|
102
|
+
# expect(chef_run).to delete_remote_directory('/tmp').with(overwrite: true)
|
103
|
+
#
|
104
|
+
# @example Assert that a +remote_directory+ was deleteed using a regex
|
105
|
+
# expect(chef_run).to delete_remote_directory('/tmp').with(overwrite: Boolean)
|
106
|
+
#
|
107
|
+
# @example Assert that a +remote_directory+ was _not_ deleteed
|
108
|
+
# expect(chef_run).to_not delete_remote_directory('/tmp')
|
109
|
+
#
|
110
|
+
#
|
111
|
+
# @param [String, Regex] resource_name
|
112
|
+
# the name of the resource to match
|
113
|
+
#
|
114
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
115
|
+
#
|
116
|
+
def delete_remote_directory(resource_name)
|
117
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_directory, :delete, resource_name)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module ChefSpec::API
|
2
|
+
# @since 1.0.0
|
3
|
+
module RemoteFileMatchers
|
4
|
+
ChefSpec::Runner.define_runner_method :remote_file
|
5
|
+
|
6
|
+
#
|
7
|
+
# Assert that a +remote_file+ resource exists in the Chef run with the
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "/tmp/config" as a
|
9
|
+
# +remote_file+:
|
10
|
+
#
|
11
|
+
# remote_file '/tmp/config' do
|
12
|
+
# action :create
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# To test the content rendered by a +remote_file+, see
|
16
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
17
|
+
#
|
18
|
+
# The Examples section demonstrates the different ways to test a
|
19
|
+
# +remote_file+ resource with ChefSpec.
|
20
|
+
#
|
21
|
+
# @example Assert that a +remote_file+ was created
|
22
|
+
# expect(chef_run).to create_remote_file('/tmp/config')
|
23
|
+
#
|
24
|
+
# @example Assert that a +remote_file+ was created with predicate matchers
|
25
|
+
# expect(chef_run).to create_remote_file('/tmp/config').with_backup(false)
|
26
|
+
#
|
27
|
+
# @example Assert that a +remote_file+ was created with attributes
|
28
|
+
# expect(chef_run).to create_remote_file('/tmp/config').with(backup: false)
|
29
|
+
#
|
30
|
+
# @example Assert that a +remote_file+ was created using a regex
|
31
|
+
# expect(chef_run).to create_remote_file('/tmp/config').with(user: /apa(.+)/)
|
32
|
+
#
|
33
|
+
# @example Assert that a +remote_file+ was _not_ created
|
34
|
+
# expect(chef_run).to_not create_remote_file('/tmp/config')
|
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 create_remote_file(resource_name)
|
43
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_file, :create, resource_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Assert that a +remote_file+ resource exists in the Chef run with the
|
48
|
+
# action +:create_if_missing+. Given a Chef Recipe that creates "/tmp/config"
|
49
|
+
# if missing as a +remote_file+:
|
50
|
+
#
|
51
|
+
# remote_file '/tmp/config' do
|
52
|
+
# action :create_if_missing
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# To test the content rendered by a +remote_file+, see
|
56
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
57
|
+
#
|
58
|
+
# The Examples section demonstrates the different ways to test a
|
59
|
+
# +remote_file+ resource with ChefSpec.
|
60
|
+
#
|
61
|
+
# @example Assert that a +remote_file+ was created if missing
|
62
|
+
# expect(chef_run).to create_remote_file_if_missing('/tmp/config')
|
63
|
+
#
|
64
|
+
# @example Assert that a +remote_file+ was created if missing with predicate matchers
|
65
|
+
# expect(chef_run).to create_remote_file_if_missing('/tmp/config').with_backup(false)
|
66
|
+
#
|
67
|
+
# @example Assert that a +remote_file+ was created if missing with attributes
|
68
|
+
# expect(chef_run).to create_remote_file_if_missing('/tmp/config').with(backup: false)
|
69
|
+
#
|
70
|
+
# @example Assert that a +remote_file+ was created if missing using a regex
|
71
|
+
# expect(chef_run).to create_remote_file_if_missing('/tmp/config').with(user: /apa(.+)/)
|
72
|
+
#
|
73
|
+
# @example Assert that a +remote_file+ was _not_ created if missing
|
74
|
+
# expect(chef_run).to_not create_remote_file('/tmp/config')
|
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 create_remote_file_if_missing(resource_name)
|
83
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_file, :create_if_missing, resource_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Assert that a +remote_file+ resource exists in the Chef run with the
|
88
|
+
# action +:delete+. Given a Chef Recipe that deletes "/tmp/config" as a
|
89
|
+
# +remote_file+:
|
90
|
+
#
|
91
|
+
# remote_file '/tmp/config' do
|
92
|
+
# action :delete
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# To test the content rendered by a +remote_file+, see
|
96
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
97
|
+
#
|
98
|
+
# The Examples section demonstrates the different ways to test a
|
99
|
+
# +remote_file+ resource with ChefSpec.
|
100
|
+
#
|
101
|
+
# @example Assert that a +remote_file+ was deleted
|
102
|
+
# expect(chef_run).to delete_remote_file('/tmp/config')
|
103
|
+
#
|
104
|
+
# @example Assert that a +remote_file+ was deleted with predicate matchers
|
105
|
+
# expect(chef_run).to delete_remote_file('/tmp/config').with_backup(false)
|
106
|
+
#
|
107
|
+
# @example Assert that a +remote_file+ was deleted with attributes
|
108
|
+
# expect(chef_run).to delete_remote_file('/tmp/config').with(backup: false)
|
109
|
+
#
|
110
|
+
# @example Assert that a +remote_file+ was deleted using a regex
|
111
|
+
# expect(chef_run).to delete_remote_file('/tmp/config').with(user: /apa(.+)/)
|
112
|
+
#
|
113
|
+
# @example Assert that a +remote_file+ was _not_ deleted
|
114
|
+
# expect(chef_run).to_not delete_remote_file('/tmp/config')
|
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 delete_remote_file(resource_name)
|
123
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_file, :delete, resource_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Assert that a +remote_file+ resource exists in the Chef run with the
|
128
|
+
# action +:touch+. Given a Chef Recipe that touches "/tmp/config" as a
|
129
|
+
# +remote_file+:
|
130
|
+
#
|
131
|
+
# remote_file '/tmp/config' do
|
132
|
+
# action :touch
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# To test the content rendered by a +remote_file+, see
|
136
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
137
|
+
#
|
138
|
+
# The Examples section demonstrates the different ways to test a
|
139
|
+
# +remote_file+ resource with ChefSpec.
|
140
|
+
#
|
141
|
+
# @example Assert that a +remote_file+ was touched
|
142
|
+
# expect(chef_run).to touch_remote_file('/tmp/config')
|
143
|
+
#
|
144
|
+
# @example Assert that a +remote_file+ was touched with predicate matchers
|
145
|
+
# expect(chef_run).to touch_remote_file('/tmp/config').with_backup(false)
|
146
|
+
#
|
147
|
+
# @example Assert that a +remote_file+ was touched with attributes
|
148
|
+
# expect(chef_run).to touch_remote_file('/tmp/config').with(backup: false)
|
149
|
+
#
|
150
|
+
# @example Assert that a +remote_file+ was touched using a regex
|
151
|
+
# expect(chef_run).to touch_remote_file('/tmp/config').with(user: /apa(.+)/)
|
152
|
+
#
|
153
|
+
# @example Assert that a +remote_file+ was _not_ touched
|
154
|
+
# expect(chef_run).to_not touch_remote_file('/tmp/config')
|
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 touch_remote_file(resource_name)
|
163
|
+
ChefSpec::Matchers::ResourceMatcher.new(:remote_file, :touch, resource_name)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|