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.
- 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
data/lib/chefspec/minitest.rb
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
module ChefSpec
|
|
2
|
-
# Supports running minitest-chef-handler examples without a real converge.
|
|
3
|
-
#
|
|
4
|
-
# This is experimental and comes with the following caveats:
|
|
5
|
-
#
|
|
6
|
-
# * This support is intended only to run existing examples at present. This
|
|
7
|
-
# means that it has not been tested with examples that explicitly create a
|
|
8
|
-
# new ChefRunner.
|
|
9
|
-
# * Examples that shell out or access the file system using Ruby will fail.
|
|
10
|
-
# This support only ensures that minitest-chef-handler matchers work.
|
|
11
|
-
# * Only a subset of minitest-chef-handler matchers are currently supported
|
|
12
|
-
# , equivalent to the built-in RSpec matchers.
|
|
13
|
-
# * It is assumed that your spec class includes the `MiniTest::Chef` modules
|
|
14
|
-
# directly. Add this include for ChefSpec mode:
|
|
15
|
-
#
|
|
16
|
-
# include ChefSpec::MiniTest
|
|
17
|
-
module MiniTest
|
|
18
|
-
|
|
19
|
-
# minitest-chef-handler declares methods for each resource that use
|
|
20
|
-
# `load_current_resource` to fetch the current state of the node. We override
|
|
21
|
-
# these and instantiate fresh resources.
|
|
22
|
-
def self.override_minitest_resources(run_context, within_module)
|
|
23
|
-
::Chef::Resource.constants.each do |resource|
|
|
24
|
-
if Chef::Resource.const_get(resource).respond_to?(:ancestors) and
|
|
25
|
-
Chef::Resource.const_get(resource).ancestors.include? Chef::Resource
|
|
26
|
-
method_name = Chef::Mixin::ConvertToClassName.
|
|
27
|
-
convert_to_snake_case(resource.to_s).to_sym
|
|
28
|
-
within_module.send(:define_method, method_name) do |name|
|
|
29
|
-
Chef::Resource.const_get(resource).new(name).tap do |r|
|
|
30
|
-
r.run_context = run_context
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# minitest-chef-handler patches `Chef::Resource` to handle file uid and gid
|
|
38
|
-
# conversion. In our instance these values are not populated by the
|
|
39
|
-
# provider and will instead be whatever was specified against the resource
|
|
40
|
-
# so we remove this conversion.
|
|
41
|
-
def self.remove_file_id_conversion
|
|
42
|
-
::Chef::Resource.class_eval do
|
|
43
|
-
def resource_value(attribute)
|
|
44
|
-
send(attribute)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def self.override_minitest_assertions(chef_run)
|
|
50
|
-
|
|
51
|
-
remove_file_id_conversion
|
|
52
|
-
|
|
53
|
-
::MiniTest::Chef::Assertions.class_eval do
|
|
54
|
-
|
|
55
|
-
def assert_includes_content(file, content)
|
|
56
|
-
assert file_includes_content?(file, content),
|
|
57
|
-
"Expected file '#{file.path}' to include the specified content"
|
|
58
|
-
file
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def refute_includes_content(file, content)
|
|
62
|
-
refute file_includes_content?(file, content),
|
|
63
|
-
"Expected file '#{file.path}' not to include the specified content"
|
|
64
|
-
file
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def assert_path_exists(file_or_dir)
|
|
68
|
-
paths = file_resources + resources_by_type(:directory)
|
|
69
|
-
actual_resource = paths.find{|file| file_or_dir.path == file.path and
|
|
70
|
-
! Array(file.action).include?(:delete)}
|
|
71
|
-
assert actual_resource, "Expected path '#{file_or_dir.path}' to exist"
|
|
72
|
-
actual_resource
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def refute_path_exists(file_or_dir)
|
|
76
|
-
paths = file_resources + resources_by_type(:directory)
|
|
77
|
-
actual_resource = paths.find{|file| file_or_dir.path == file.path and
|
|
78
|
-
Array(file.action).include?(:delete)}
|
|
79
|
-
assert actual_resource, "Expected path '#{file_or_dir.path}' not to exist"
|
|
80
|
-
actual_resource
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
private
|
|
84
|
-
|
|
85
|
-
def same_resource_type?(expected_resource, actual_resource)
|
|
86
|
-
case actual_resource.resource_name.to_s
|
|
87
|
-
when /file$/
|
|
88
|
-
expected_resource.resource_name == :file
|
|
89
|
-
else
|
|
90
|
-
expected_resource.resource_name == actual_resource.resource_name
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def find_resource(expected_resource, field)
|
|
95
|
-
resources.find do |actual_resource|
|
|
96
|
-
same_resource_type?(expected_resource, actual_resource) and
|
|
97
|
-
expected_resource.send(field) == actual_resource.send(field)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def self.override_assertion(assert_name, field, wont_actions = [])
|
|
102
|
-
[:assert, :refute].each do |prefix|
|
|
103
|
-
define_method("#{prefix}_#{assert_name}") do |expected_resource|
|
|
104
|
-
actual_resource = find_resource(expected_resource, field)
|
|
105
|
-
is_wont = false
|
|
106
|
-
if actual_resource
|
|
107
|
-
is_wont = ! (Array(actual_resource.action) & wont_actions).empty?
|
|
108
|
-
end
|
|
109
|
-
# If we are refuting then the assertion is actually positive,
|
|
110
|
-
# we are for example asserting that the package has the `:remove`
|
|
111
|
-
# action.
|
|
112
|
-
if prefix == :assert || is_wont
|
|
113
|
-
assert actual_resource
|
|
114
|
-
else
|
|
115
|
-
refute actual_resource
|
|
116
|
-
end
|
|
117
|
-
actual_resource
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
override_assertion :installed, :package_name, [:remove, :purge]
|
|
123
|
-
override_assertion :enabled, :enabled, [:disable]
|
|
124
|
-
override_assertion :running, :running, [:stop]
|
|
125
|
-
override_assertion :user_exists, :username, [:remove]
|
|
126
|
-
override_assertion :group_exists, :group_name, [:remove]
|
|
127
|
-
|
|
128
|
-
def file_resources
|
|
129
|
-
resources.select{|r| r.resource_name.to_s.end_with?('file')} +
|
|
130
|
-
resources.select{|r| r.resource_name == :template}
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def resources_by_type(type)
|
|
134
|
-
resources.select{|r| r.resource_name == type}
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def cookbook_files(cookbook)
|
|
138
|
-
run_context.cookbook_collection[cookbook].file_filenames
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def file_includes_content?(file, content)
|
|
142
|
-
file_resources.any? do |f|
|
|
143
|
-
f.path == file.path &&
|
|
144
|
-
case f.resource_name
|
|
145
|
-
when :cookbook_file
|
|
146
|
-
content_from_cookbook_file(chef_run, f)
|
|
147
|
-
when :file
|
|
148
|
-
content_from_file(chef_run, f)
|
|
149
|
-
when :template
|
|
150
|
-
content_from_template(chef_run, f)
|
|
151
|
-
else raise NotImplementedError,
|
|
152
|
-
":#{f.resource_name} not supported for comparison"
|
|
153
|
-
end.include?(content)
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def self.share_object(spec_mod, name, obj)
|
|
161
|
-
spec_mod.send(:define_method, name) do
|
|
162
|
-
obj
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def self.included(other_mod)
|
|
167
|
-
self.support_fake_converge(other_mod) if spec_module?(other_mod)
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def self.support_fake_converge(spec_mod)
|
|
171
|
-
chef_run = ChefSpec::ChefRunner.new(
|
|
172
|
-
:cookbook_path => default_cookbook_path).converge recipe_for_module(spec_mod)
|
|
173
|
-
override_minitest_resources(chef_run.run_context, spec_mod)
|
|
174
|
-
override_minitest_assertions(chef_run)
|
|
175
|
-
share_object(spec_mod, :chef_run, chef_run)
|
|
176
|
-
share_object(spec_mod, :node, chef_run.node)
|
|
177
|
-
share_object(spec_mod, :resources, chef_run.resources)
|
|
178
|
-
share_object(spec_mod, :run_context, chef_run.run_context)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def self.recipe_for_module(mod)
|
|
182
|
-
mod.to_s.split('::')[-2..-1].join('::')
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def self.spec_module?(mod)
|
|
186
|
-
# minitest-chef-handler module names are of the form:
|
|
187
|
-
# `recipe::example::default`
|
|
188
|
-
recipe_for_module(mod) == recipe_for_module(mod).downcase
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def self.default_cookbook_path
|
|
192
|
-
Pathname.new(File.join(caller(3).first.split(':').slice(0..-3).first, "..", "..", "..")).cleanpath
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class Chef
|
|
2
|
-
class Resource
|
|
3
|
-
class Conditional
|
|
4
|
-
alias_method :original_evaluate_command, :evaluate_command
|
|
5
|
-
def evaluate_command
|
|
6
|
-
runner.stubbed_commands.each do |stubbed_cmd, result|
|
|
7
|
-
case command
|
|
8
|
-
when stubbed_cmd then return result
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
if runner.actually_run_shell_guards?
|
|
12
|
-
return original_evaluate_command
|
|
13
|
-
end
|
|
14
|
-
raise RSpec::Mocks::MockExpectationError.new(
|
|
15
|
-
"The following shell guard was unstubbed: #{description}")
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Ruby stdlib Hash class
|
|
2
|
-
class Hash
|
|
3
|
-
# Monkey-patch to stdlib Hash to give us Mash style lookup
|
|
4
|
-
def method_missing(m, *args, &block)
|
|
5
|
-
if has_key?(m.to_sym)
|
|
6
|
-
self[m.to_sym]
|
|
7
|
-
elsif has_key?(m.to_s)
|
|
8
|
-
self[m.to_s]
|
|
9
|
-
else
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Monkey-patch to stdlib Hash to correspond to Mash-style lookup
|
|
15
|
-
# @see {Hash#respond_to?}
|
|
16
|
-
def respond_to?(m, include_private = false)
|
|
17
|
-
if has_key?(m.to_sym) || has_key?(m.to_s)
|
|
18
|
-
true
|
|
19
|
-
else
|
|
20
|
-
super
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
if Chef::VERSION >= '11.0.0'
|
|
2
|
-
|
|
3
|
-
# Override Chef LWRP creation to remove existing class to avoid redefinition warnings.
|
|
4
|
-
class Chef
|
|
5
|
-
class Provider
|
|
6
|
-
# Chef provider for a resource
|
|
7
|
-
class LWRPBase < Provider
|
|
8
|
-
class << self
|
|
9
|
-
alias_method :old_build_from_file, :build_from_file
|
|
10
|
-
|
|
11
|
-
# Override Opscode provider to remove any existing LWRP
|
|
12
|
-
#
|
|
13
|
-
# @param [String] cookbook_name The name of the cookbook
|
|
14
|
-
# @param [String] filename File to load as a LWRP
|
|
15
|
-
# @param [Chef::RunContext] run_context Context of a Chef Run
|
|
16
|
-
# @return [Chef::Provider] the created provider
|
|
17
|
-
def build_from_file(*args)
|
|
18
|
-
cookbook_name, filename = args[0,2]
|
|
19
|
-
remove_existing_lwrp(convert_to_class_name(filename_to_qualified_string(cookbook_name, filename)))
|
|
20
|
-
old_build_from_file(*args)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Remove any existing Chef provider or resource with the specified name.
|
|
24
|
-
#
|
|
25
|
-
# @param [String] class_name The class name. Must be a valid constant name.
|
|
26
|
-
def remove_existing_lwrp(class_name)
|
|
27
|
-
[Chef::Resource::LWRPBase, Chef::Provider::LWRPBase, Chef::Resource, Chef::Provider].each do |resource_holder|
|
|
28
|
-
if RUBY_VERSION < '1.9'
|
|
29
|
-
if resource_holder.const_defined? class_name
|
|
30
|
-
resource_holder.send(:remove_const, class_name)
|
|
31
|
-
end
|
|
32
|
-
else
|
|
33
|
-
if resource_holder.const_defined? class_name, false
|
|
34
|
-
resource_holder.send(:remove_const, class_name)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
if Chef::VERSION < '11.0.0'
|
|
2
|
-
|
|
3
|
-
# Override Chef LWRP creation to remove existing class to avoid redefinition warnings.
|
|
4
|
-
class Chef
|
|
5
|
-
# Chef provider for a resource
|
|
6
|
-
class Provider
|
|
7
|
-
class << self
|
|
8
|
-
alias_method :old_build_from_file, :build_from_file
|
|
9
|
-
|
|
10
|
-
# Override Opscode provider to remove any existing LWRP
|
|
11
|
-
#
|
|
12
|
-
# @param [String] cookbook_name The name of the cookbook
|
|
13
|
-
# @param [String] filename File to load as a LWRP
|
|
14
|
-
# @param [Chef::RunContext] run_context Context of a Chef Run
|
|
15
|
-
# @return [Chef::Provider] the created provider
|
|
16
|
-
def build_from_file(*args)
|
|
17
|
-
cookbook_name, filename = args[0,2]
|
|
18
|
-
remove_existing_lwrp(convert_to_class_name(filename_to_qualified_string(cookbook_name, filename)))
|
|
19
|
-
old_build_from_file(*args)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Remove any existing Chef provider or resource with the specified name.
|
|
23
|
-
#
|
|
24
|
-
# @param [String] class_name The class name. Must be a valid constant name.
|
|
25
|
-
def remove_existing_lwrp(class_name)
|
|
26
|
-
[Chef::Resource, Chef::Provider].each do |resource_holder|
|
|
27
|
-
if RUBY_VERSION < '1.9'
|
|
28
|
-
if resource_holder.const_defined? class_name
|
|
29
|
-
resource_holder.send(:remove_const, class_name)
|
|
30
|
-
end
|
|
31
|
-
else
|
|
32
|
-
if resource_holder.const_defined? class_name, false
|
|
33
|
-
resource_holder.send(:remove_const, class_name)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|