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,154 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module EasyInstallPackageMatchers
4
+ ChefSpec::Runner.define_runner_method :easy_install_package
5
+
6
+ #
7
+ # Assert that an +easy_install_package+ resource exists in the Chef run
8
+ # with the action +:install+. Given a Chef Recipe that installs "pygments" as a
9
+ # +easy_install_package+:
10
+ #
11
+ # easy_install_package 'pygments' do
12
+ # action :install
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test a
16
+ # +easy_install_package+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that an +easy_install_package+ was installed
19
+ # expect(chef_run).to install_easy_install_package('pygments')
20
+ #
21
+ # @example Assert that an +easy_install_package+ was installed with predicate matchers
22
+ # expect(chef_run).to install_easy_install_package('pygments').with_version('1.2.3')
23
+ #
24
+ # @example Assert that an +easy_install_package+ was installed with attributes
25
+ # expect(chef_run).to install_easy_install_package('pygments').with(version: '1.2.3')
26
+ #
27
+ # @example Assert that an +easy_install_package+ was installed using a regex
28
+ # expect(chef_run).to install_easy_install_package('pygments').with(version: /(\d+\.){2}\.\d+/)
29
+ #
30
+ # @example Assert that an +easy_install_package+ was _not_ installed
31
+ # expect(chef_run).to_not install_easy_install_package('pygments')
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_easy_install_package(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:easy_install_package, :install, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that an +easy_install_package+ resource exists in the Chef run
45
+ # with the action +:purge+. Given a Chef Recipe that purges "pygments" as a
46
+ # +easy_install_package+:
47
+ #
48
+ # easy_install_package 'pygments' do
49
+ # action :purge
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test a
53
+ # +easy_install_package+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that an +easy_install_package+ was purged
56
+ # expect(chef_run).to purge_easy_install_package('pygments')
57
+ #
58
+ # @example Assert that an +easy_install_package+ was purged with predicate matchers
59
+ # expect(chef_run).to purge_easy_install_package('pygments').with_version('1.2.3')
60
+ #
61
+ # @example Assert that an +easy_install_package+ was purged with attributes
62
+ # expect(chef_run).to purge_easy_install_package('pygments').with(version: '1.2.3')
63
+ #
64
+ # @example Assert that an +easy_install_package+ was purged using a regex
65
+ # expect(chef_run).to purge_easy_install_package('pygments').with(version: /(\d+\.){2}\.\d+/)
66
+ #
67
+ # @example Assert that an +easy_install_package+ was _not_ purged
68
+ # expect(chef_run).to_not purge_easy_install_package('pygments')
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_easy_install_package(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:easy_install_package, :purge, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that an +easy_install_package+ resource exists in the Chef run
82
+ # with the action +:remove+. Given a Chef Recipe that removes "pygments" as a
83
+ # +easy_install_package+:
84
+ #
85
+ # easy_install_package 'pygments' do
86
+ # action :remove
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test a
90
+ # +easy_install_package+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that an +easy_install_package+ was removed
93
+ # expect(chef_run).to remove_easy_install_package('pygments')
94
+ #
95
+ # @example Assert that an +easy_install_package+ was removed with predicate matchers
96
+ # expect(chef_run).to remove_easy_install_package('pygments').with_version('1.2.3')
97
+ #
98
+ # @example Assert that an +easy_install_package+ was removed with attributes
99
+ # expect(chef_run).to remove_easy_install_package('pygments').with(version: '1.2.3')
100
+ #
101
+ # @example Assert that an +easy_install_package+ was removed using a regex
102
+ # expect(chef_run).to remove_easy_install_package('pygments').with(version: /(\d+\.){2}\.\d+/)
103
+ #
104
+ # @example Assert that an +easy_install_package+ was _not_ removed
105
+ # expect(chef_run).to_not remove_easy_install_package('pygments')
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_easy_install_package(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:easy_install_package, :remove, resource_name)
115
+ end
116
+
117
+ #
118
+ # Assert that an +easy_install_package+ resource exists in the Chef run
119
+ # with the action +:upgrade+. Given a Chef Recipe that upgrades "pygments" as a
120
+ # +easy_install_package+:
121
+ #
122
+ # easy_install_package 'pygments' do
123
+ # action :upgrade
124
+ # end
125
+ #
126
+ # The Examples section demonstrates the different ways to test a
127
+ # +easy_install_package+ resource with ChefSpec.
128
+ #
129
+ # @example Assert that an +easy_install_package+ was upgraded
130
+ # expect(chef_run).to upgrade_easy_install_package('pygments')
131
+ #
132
+ # @example Assert that an +easy_install_package+ was upgraded with predicate matchers
133
+ # expect(chef_run).to upgrade_easy_install_package('pygments').with_version('1.2.3')
134
+ #
135
+ # @example Assert that an +easy_install_package+ was upgraded with attributes
136
+ # expect(chef_run).to upgrade_easy_install_package('pygments').with(version: '1.2.3')
137
+ #
138
+ # @example Assert that an +easy_install_package+ was upgraded using a regex
139
+ # expect(chef_run).to upgrade_easy_install_package('pygments').with(version: /(\d+\.){2}\.\d+/)
140
+ #
141
+ # @example Assert that an +easy_install_package+ was _not_ upgraded
142
+ # expect(chef_run).to_not upgrade_easy_install_package('pygments')
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_easy_install_package(resource_name)
151
+ ChefSpec::Matchers::ResourceMatcher.new(:easy_install_package, :upgrade, resource_name)
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,117 @@
1
+ module ChefSpec::API
2
+ # @since 0.9.0
3
+ module EnvMatchers
4
+ ChefSpec::Runner.define_runner_method :env
5
+
6
+ #
7
+ # Assert that an +env+ resource exists in the Chef run with the
8
+ # action +:create+. Given a Chef Recipe that creates "HOME" as an
9
+ # +env+:
10
+ #
11
+ # env 'HOME' do
12
+ # action :create
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test an
16
+ # +env+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that an +env+ was created
19
+ # expect(chef_run).to create_env('HOME')
20
+ #
21
+ # @example Assert that an +env+ was created with predicate matchers
22
+ # expect(chef_run).to create_env('HOME').with_value('/home')
23
+ #
24
+ # @example Assert that an +env+ was created with attributes
25
+ # expect(chef_run).to create_env('HOME').with(value: 'home')
26
+ #
27
+ # @example Assert that an +env+ was created using a regex
28
+ # expect(chef_run).to create_env('HOME').with(value: /\/ho(.+)/)
29
+ #
30
+ # @example Assert that an +env+ was _not_ created
31
+ # expect(chef_run).to_not create_env('HOME')
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_env(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:env, :create, resource_name)
41
+ end
42
+
43
+ #
44
+ # Assert that an +env+ resource exists in the Chef run with the
45
+ # action +:delete+. Given a Chef Recipe that deletes "HOME" as an
46
+ # +env+:
47
+ #
48
+ # env 'HOME' do
49
+ # action :delete
50
+ # end
51
+ #
52
+ # The Examples section demonstrates the different ways to test an
53
+ # +env+ resource with ChefSpec.
54
+ #
55
+ # @example Assert that an +env+ was deleted
56
+ # expect(chef_run).to delete_env('HOME')
57
+ #
58
+ # @example Assert that an +env+ was deleted with predicate matchers
59
+ # expect(chef_run).to delete_env('HOME').with_value('/home')
60
+ #
61
+ # @example Assert that an +env+ was deleted with attributes
62
+ # expect(chef_run).to delete_env('HOME').with(value: 'home')
63
+ #
64
+ # @example Assert that an +env+ was deleted using a regex
65
+ # expect(chef_run).to delete_env('HOME').with(value: /\/ho(.+)/)
66
+ #
67
+ # @example Assert that an +env+ was _not_ deleted
68
+ # expect(chef_run).to_not delete_env('HOME')
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_env(resource_name)
77
+ ChefSpec::Matchers::ResourceMatcher.new(:env, :delete, resource_name)
78
+ end
79
+
80
+ #
81
+ # Assert that an +env+ resource exists in the Chef run with the
82
+ # action +:modify+. Given a Chef Recipe that modifies "HOME" as an
83
+ # +env+:
84
+ #
85
+ # env 'HOME' do
86
+ # action :modify
87
+ # end
88
+ #
89
+ # The Examples section demonstrates the different ways to test an
90
+ # +env+ resource with ChefSpec.
91
+ #
92
+ # @example Assert that an +env+ was modified
93
+ # expect(chef_run).to modify_env('HOME')
94
+ #
95
+ # @example Assert that an +env+ was modified with predicate matchers
96
+ # expect(chef_run).to modify_env('HOME').with_value('/home')
97
+ #
98
+ # @example Assert that an +env+ was modified with attributes
99
+ # expect(chef_run).to modify_env('HOME').with(value: 'home')
100
+ #
101
+ # @example Assert that an +env+ was modified using a regex
102
+ # expect(chef_run).to modify_env('HOME').with(value: /\/ho(.+)/)
103
+ #
104
+ # @example Assert that an +env+ was _not_ modified
105
+ # expect(chef_run).to_not modify_env('HOME')
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 modify_env(resource_name)
114
+ ChefSpec::Matchers::ResourceMatcher.new(:env, :modify, resource_name)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,43 @@
1
+ module ChefSpec::API
2
+ # @since 3.0.0
3
+ module ErlCallMatchers
4
+ ChefSpec::Runner.define_runner_method :erl_call
5
+
6
+ #
7
+ # Assert that an +erl_call+ resource exists in the Chef run with the
8
+ # action +:run+. Given a Chef Recipe that runs "net_adm:names()" as an
9
+ # +erl_call+:
10
+ #
11
+ # erl_call 'net_adm:names()' do
12
+ # action :run
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test an
16
+ # +erl_call+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that an +erl_call+ was runed
19
+ # expect(chef_run).to run_erl_call('net_adm:names()')
20
+ #
21
+ # @example Assert that an +erl_call+ was runed with predicate matchers
22
+ # expect(chef_run).to run_erl_call('net_adm:names()').with_node_name('example')
23
+ #
24
+ # @example Assert that an +erl_call+ was runed with attributes
25
+ # expect(chef_run).to run_erl_call('net_adm:names()').with(node_name: 'example')
26
+ #
27
+ # @example Assert that an +erl_call+ was runed using a regex
28
+ # expect(chef_run).to run_erl_call('net_adm:names()').with(node_name: /[a-z]+/)
29
+ #
30
+ # @example Assert that an +erl_call+ was _not_ runed
31
+ # expect(chef_run).to_not run_erl_call('net_adm:names()')
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_erl_call(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:erl_call, :run, resource_name)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ module ChefSpec::API
2
+ # @since 0.0.1
3
+ module ExecuteMatchers
4
+ ChefSpec::Runner.define_runner_method :execute
5
+
6
+ #
7
+ # Assert that an +execute+ resource exists in the Chef run with the
8
+ # action +:run+. Given a Chef Recipe that runs "echo "hello"" as an
9
+ # +execute+:
10
+ #
11
+ # execute 'echo "hello"' do
12
+ # action :run
13
+ # end
14
+ #
15
+ # The Examples section demonstrates the different ways to test an
16
+ # +execute+ resource with ChefSpec.
17
+ #
18
+ # @example Assert that an +execute+ was runed
19
+ # expect(chef_run).to run_execute('echo "hello"')
20
+ #
21
+ # @example Assert that an +execute+ was runed with predicate matchers
22
+ # expect(chef_run).to run_execute('echo "hello"').with_user('svargo')
23
+ #
24
+ # @example Assert that an +execute+ was runed with attributes
25
+ # expect(chef_run).to run_execute('echo "hello"').with(user: 'svargo')
26
+ #
27
+ # @example Assert that an +execute+ was runed using a regex
28
+ # expect(chef_run).to run_execute('echo "hello"').with(user: /sva(.+)/)
29
+ #
30
+ # @example Assert that an +execute+ was _not_ runed
31
+ # expect(chef_run).to_not run_execute('echo "hello"')
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_execute(resource_name)
40
+ ChefSpec::Matchers::ResourceMatcher.new(:execute, :run, resource_name)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,166 @@
1
+ module ChefSpec::API
2
+ # @since 0.0.1
3
+ module FileMatchers
4
+ ChefSpec::Runner.define_runner_method :file
5
+
6
+ #
7
+ # Assert that a +file+ resource exists in the Chef run with the
8
+ # action +:create+. Given a Chef Recipe that creates "/tmp/config" as a
9
+ # +file+:
10
+ #
11
+ # file '/tmp/config' do
12
+ # action :create
13
+ # end
14
+ #
15
+ # To test the content rendered by a +file+, see
16
+ # {ChefSpec::API::RenderFileMatchers}.
17
+ #
18
+ # The Examples section demonstrates the different ways to test a
19
+ # +file+ resource with ChefSpec.
20
+ #
21
+ # @example Assert that a +file+ was created
22
+ # expect(chef_run).to create_file('/tmp/config')
23
+ #
24
+ # @example Assert that a +file+ was created with predicate matchers
25
+ # expect(chef_run).to create_file('/tmp/config').with_backup(false)
26
+ #
27
+ # @example Assert that a +file+ was created with attributes
28
+ # expect(chef_run).to create_file('/tmp/config').with(backup: false)
29
+ #
30
+ # @example Assert that a +file+ was created using a regex
31
+ # expect(chef_run).to create_file('/tmp/config').with(user: /apa(.+)/)
32
+ #
33
+ # @example Assert that a +file+ was _not_ created
34
+ # expect(chef_run).to_not create_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_file(resource_name)
43
+ ChefSpec::Matchers::ResourceMatcher.new(:file, :create, resource_name)
44
+ end
45
+
46
+ #
47
+ # Assert that a +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 +file+:
50
+ #
51
+ # file '/tmp/config' do
52
+ # action :create_if_missing
53
+ # end
54
+ #
55
+ # To test the content rendered by a +file+, see
56
+ # {ChefSpec::API::RenderFileMatchers}.
57
+ #
58
+ # The Examples section demonstrates the different ways to test a
59
+ # +file+ resource with ChefSpec.
60
+ #
61
+ # @example Assert that a +file+ was created if missing
62
+ # expect(chef_run).to create_file_if_missing('/tmp/config')
63
+ #
64
+ # @example Assert that a +file+ was created if missing with predicate matchers
65
+ # expect(chef_run).to create_file_if_missing('/tmp/config').with_backup(false)
66
+ #
67
+ # @example Assert that a +file+ was created if missing with attributes
68
+ # expect(chef_run).to create_file_if_missing('/tmp/config').with(backup: false)
69
+ #
70
+ # @example Assert that a +file+ was created if missing using a regex
71
+ # expect(chef_run).to create_file_if_missing('/tmp/config').with(user: /apa(.+)/)
72
+ #
73
+ # @example Assert that a +file+ was _not_ created if missing
74
+ # expect(chef_run).to_not create_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_file_if_missing(resource_name)
83
+ ChefSpec::Matchers::ResourceMatcher.new(:file, :create_if_missing, resource_name)
84
+ end
85
+
86
+ #
87
+ # Assert that a +file+ resource exists in the Chef run with the
88
+ # action +:delete+. Given a Chef Recipe that deletes "/tmp/config" as a
89
+ # +file+:
90
+ #
91
+ # file '/tmp/config' do
92
+ # action :delete
93
+ # end
94
+ #
95
+ # To test the content rendered by a +file+, see
96
+ # {ChefSpec::API::RenderFileMatchers}.
97
+ #
98
+ # The Examples section demonstrates the different ways to test a
99
+ # +file+ resource with ChefSpec.
100
+ #
101
+ # @example Assert that a +file+ was deleted
102
+ # expect(chef_run).to delete_file('/tmp/config')
103
+ #
104
+ # @example Assert that a +file+ was deleted with predicate matchers
105
+ # expect(chef_run).to delete_file('/tmp/config').with_backup(false)
106
+ #
107
+ # @example Assert that a +file+ was deleted with attributes
108
+ # expect(chef_run).to delete_file('/tmp/config').with(backup: false)
109
+ #
110
+ # @example Assert that a +file+ was deleted using a regex
111
+ # expect(chef_run).to delete_file('/tmp/config').with(user: /apa(.+)/)
112
+ #
113
+ # @example Assert that a +file+ was _not_ deleted
114
+ # expect(chef_run).to_not delete_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_file(resource_name)
123
+ ChefSpec::Matchers::ResourceMatcher.new(:file, :delete, resource_name)
124
+ end
125
+
126
+ #
127
+ # Assert that a +file+ resource exists in the Chef run with the
128
+ # action +:touch+. Given a Chef Recipe that touches "/tmp/config" as a
129
+ # +file+:
130
+ #
131
+ # file '/tmp/config' do
132
+ # action :touch
133
+ # end
134
+ #
135
+ # To test the content rendered by a +file+, see
136
+ # {ChefSpec::API::RenderFileMatchers}.
137
+ #
138
+ # The Examples section demonstrates the different ways to test a
139
+ # +file+ resource with ChefSpec.
140
+ #
141
+ # @example Assert that a +file+ was touched
142
+ # expect(chef_run).to touch_file('/tmp/config')
143
+ #
144
+ # @example Assert that a +file+ was touched with predicate matchers
145
+ # expect(chef_run).to touch_file('/tmp/config').with_backup(false)
146
+ #
147
+ # @example Assert that a +file+ was touched with attributes
148
+ # expect(chef_run).to touch_file('/tmp/config').with(backup: false)
149
+ #
150
+ # @example Assert that a +file+ was touched using a regex
151
+ # expect(chef_run).to touch_file('/tmp/config').with(user: /apa(.+)/)
152
+ #
153
+ # @example Assert that a +file+ was _not_ touched
154
+ # expect(chef_run).to_not touch_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_file(resource_name)
163
+ ChefSpec::Matchers::ResourceMatcher.new(:file, :touch, resource_name)
164
+ end
165
+ end
166
+ end