chefspec 4.0.2 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +19 -0
- data/README.md +84 -87
- data/chefspec.gemspec +1 -1
- data/examples/apt_package/spec/install_spec.rb +1 -1
- data/examples/apt_package/spec/purge_spec.rb +1 -1
- data/examples/apt_package/spec/reconfig_spec.rb +1 -1
- data/examples/apt_package/spec/remove_spec.rb +1 -1
- data/examples/apt_package/spec/upgrade_spec.rb +1 -1
- data/examples/attributes/spec/default_spec.rb +1 -1
- data/examples/batch/spec/run_spec.rb +1 -1
- data/examples/cached/spec/default_spec.rb +1 -1
- data/examples/chef_gem/spec/install_spec.rb +1 -1
- data/examples/chef_gem/spec/purge_spec.rb +1 -1
- data/examples/chef_gem/spec/reconfig_spec.rb +1 -1
- data/examples/chef_gem/spec/remove_spec.rb +1 -1
- data/examples/chef_gem/spec/upgrade_spec.rb +1 -1
- data/examples/compile_time/spec/default_spec.rb +1 -1
- data/examples/cookbook_file/spec/create_if_missing_spec.rb +1 -1
- data/examples/cookbook_file/spec/create_spec.rb +1 -1
- data/examples/cookbook_file/spec/delete_spec.rb +1 -1
- data/examples/cookbook_file/spec/touch_spec.rb +1 -1
- data/examples/cron/spec/create_spec.rb +1 -1
- data/examples/cron/spec/delete_spec.rb +1 -1
- data/examples/custom_matcher/libraries/matcher.rb +1 -1
- data/examples/custom_matcher/spec/install_spec.rb +1 -1
- data/examples/custom_matcher/spec/remove_spec.rb +1 -1
- data/examples/deploy/spec/deploy_spec.rb +1 -1
- data/examples/deploy/spec/force_deploy_spec.rb +1 -1
- data/examples/deploy/spec/rollback_spec.rb +1 -1
- data/examples/directory/spec/create_spec.rb +1 -1
- data/examples/directory/spec/delete_spec.rb +1 -1
- data/examples/do_nothing/spec/default_spec.rb +1 -1
- data/examples/dpkg_package/spec/install_spec.rb +1 -1
- data/examples/dpkg_package/spec/purge_spec.rb +1 -1
- data/examples/dpkg_package/spec/remove_spec.rb +1 -1
- data/examples/easy_install_package/spec/install_spec.rb +1 -1
- data/examples/easy_install_package/spec/purge_spec.rb +1 -1
- data/examples/easy_install_package/spec/remove_spec.rb +1 -1
- data/examples/easy_install_package/spec/upgrade_spec.rb +1 -1
- data/examples/env/spec/create_spec.rb +1 -1
- data/examples/env/spec/delete_spec.rb +1 -1
- data/examples/env/spec/modify_spec.rb +1 -1
- data/examples/erl_call/spec/run_spec.rb +1 -1
- data/examples/execute/spec/run_spec.rb +1 -1
- data/examples/expect_exception/spec/compile_error_spec.rb +1 -1
- data/examples/expect_exception/spec/converge_error_spec.rb +1 -1
- data/examples/expect_exception/spec/no_error_spec.rb +1 -1
- data/examples/file/spec/create_if_missing_spec.rb +1 -1
- data/examples/file/spec/create_spec.rb +1 -1
- data/examples/file/spec/delete_spec.rb +1 -1
- data/examples/file/spec/touch_spec.rb +1 -1
- data/examples/freebsd_package/spec/install_spec.rb +1 -1
- data/examples/freebsd_package/spec/remove_spec.rb +1 -1
- data/examples/gem_package/spec/install_spec.rb +1 -1
- data/examples/gem_package/spec/purge_spec.rb +1 -1
- data/examples/gem_package/spec/reconfig_spec.rb +1 -1
- data/examples/gem_package/spec/remove_spec.rb +1 -1
- data/examples/gem_package/spec/upgrade_spec.rb +1 -1
- data/examples/git/spec/checkout_spec.rb +1 -1
- data/examples/git/spec/export_spec.rb +1 -1
- data/examples/git/spec/sync_spec.rb +1 -1
- data/examples/group/spec/create_spec.rb +1 -1
- data/examples/group/spec/manage_spec.rb +1 -1
- data/examples/group/spec/modify_spec.rb +1 -1
- data/examples/group/spec/remove_spec.rb +1 -1
- data/examples/guards/spec/default_spec.rb +1 -1
- data/examples/heavy_provider_light_resource/spec/provider_service_spec.rb +1 -1
- data/examples/http_request/spec/delete_spec.rb +1 -1
- data/examples/http_request/spec/get_spec.rb +1 -1
- data/examples/http_request/spec/head_spec.rb +1 -1
- data/examples/http_request/spec/options_spec.rb +1 -1
- data/examples/http_request/spec/post_spec.rb +1 -1
- data/examples/http_request/spec/put_spec.rb +1 -1
- data/examples/ifconfig/spec/add_spec.rb +1 -1
- data/examples/ifconfig/spec/delete_spec.rb +1 -1
- data/examples/ifconfig/spec/disable_spec.rb +1 -1
- data/examples/ifconfig/spec/enable_spec.rb +1 -1
- data/examples/include_recipe/spec/default_spec.rb +1 -1
- data/examples/inherits/spec/default_spec.rb +1 -1
- data/examples/ips_package/spec/install_spec.rb +1 -1
- data/examples/ips_package/spec/remove_spec.rb +1 -1
- data/examples/ips_package/spec/upgrade_spec.rb +1 -1
- data/examples/link/spec/create_spec.rb +1 -1
- data/examples/link/spec/delete_spec.rb +1 -1
- data/examples/link/spec/link_to_spec.rb +1 -1
- data/examples/log/spec/write_spec.rb +1 -1
- data/examples/macports_package/spec/install_spec.rb +1 -1
- data/examples/macports_package/spec/purge_spec.rb +1 -1
- data/examples/macports_package/spec/remove_spec.rb +1 -1
- data/examples/macports_package/spec/upgrade_spec.rb +1 -1
- data/examples/mdadm/spec/assemble_spec.rb +1 -1
- data/examples/mdadm/spec/create_spec.rb +1 -1
- data/examples/mdadm/spec/stop_spec.rb +1 -1
- data/examples/mount/spec/disable_spec.rb +1 -1
- data/examples/mount/spec/enable_spec.rb +1 -1
- data/examples/mount/spec/mount_spec.rb +1 -1
- data/examples/mount/spec/remount_spec.rb +1 -1
- data/examples/mount/spec/umount_spec.rb +1 -1
- data/examples/multiple_actions/spec/default_spec.rb +1 -1
- data/examples/multiple_actions/spec/sequential_spec.rb +4 -1
- data/examples/multiple_run_action/spec/default_spec.rb +1 -1
- data/examples/notifications/spec/chained_spec.rb +1 -1
- data/examples/notifications/spec/default_spec.rb +1 -1
- data/examples/notifications/spec/delayed_spec.rb +1 -1
- data/examples/notifications/spec/immediately_spec.rb +1 -1
- data/examples/ohai/spec/reload_spec.rb +1 -1
- data/examples/package/spec/install_spec.rb +1 -1
- data/examples/package/spec/purge_spec.rb +1 -1
- data/examples/package/spec/reconfig_spec.rb +1 -1
- data/examples/package/spec/remove_spec.rb +1 -1
- data/examples/package/spec/upgrade_spec.rb +1 -1
- data/examples/pacman_package/spec/install_spec.rb +1 -1
- data/examples/pacman_package/spec/purge_spec.rb +1 -1
- data/examples/pacman_package/spec/remove_spec.rb +1 -1
- data/examples/pacman_package/spec/upgrade_spec.rb +1 -1
- data/examples/portage_package/spec/install_spec.rb +1 -1
- data/examples/portage_package/spec/purge_spec.rb +1 -1
- data/examples/portage_package/spec/remove_spec.rb +1 -1
- data/examples/portage_package/spec/upgrade_spec.rb +1 -1
- data/examples/powershell_script/spec/run_spec.rb +1 -1
- data/examples/registry_key/spec/create_if_missing_spec.rb +1 -1
- data/examples/registry_key/spec/create_spec.rb +1 -1
- data/examples/registry_key/spec/delete_key_spec.rb +1 -1
- data/examples/registry_key/spec/delete_spec.rb +1 -1
- data/examples/remote_directory/spec/create_if_missing_spec.rb +1 -1
- data/examples/remote_directory/spec/create_spec.rb +1 -1
- data/examples/remote_directory/spec/delete_spec.rb +1 -1
- data/examples/remote_file/spec/create_if_missing_spec.rb +1 -1
- data/examples/remote_file/spec/create_spec.rb +1 -1
- data/examples/remote_file/spec/delete_spec.rb +1 -1
- data/examples/remote_file/spec/touch_spec.rb +1 -1
- data/examples/render_file/spec/default_spec.rb +1 -1
- data/examples/render_file/spec/template_helpers_spec.rb +1 -1
- data/examples/roles/spec/default_spec.rb +1 -1
- data/examples/route/spec/add_spec.rb +1 -1
- data/examples/route/spec/delete_spec.rb +1 -1
- data/examples/rpm_package/spec/install_spec.rb +1 -1
- data/examples/rpm_package/spec/remove_spec.rb +1 -1
- data/examples/rpm_package/spec/upgrade_spec.rb +1 -1
- data/examples/ruby_block/spec/run_spec.rb +1 -1
- data/examples/script/spec/run_bash_spec.rb +1 -1
- data/examples/script/spec/run_csh_spec.rb +1 -1
- data/examples/script/spec/run_perl_spec.rb +1 -1
- data/examples/script/spec/run_python_spec.rb +1 -1
- data/examples/script/spec/run_ruby_spec.rb +1 -1
- data/examples/script/spec/run_script_spec.rb +1 -1
- data/examples/server/spec/client_spec.rb +5 -4
- data/examples/server/spec/data_bag_spec.rb +10 -9
- data/examples/server/spec/environment_spec.rb +5 -4
- data/examples/server/spec/node_spec.rb +20 -14
- data/examples/server/spec/render_with_cached_spec.rb +1 -2
- data/examples/server/spec/role_spec.rb +5 -4
- data/examples/server/spec/search_spec.rb +7 -8
- data/examples/service/spec/disable_spec.rb +1 -1
- data/examples/service/spec/enable_spec.rb +1 -1
- data/examples/service/spec/reload_spec.rb +1 -1
- data/examples/service/spec/restart_spec.rb +1 -1
- data/examples/service/spec/start_spec.rb +1 -1
- data/examples/service/spec/stop_spec.rb +1 -1
- data/examples/smartos_package/spec/install_spec.rb +1 -1
- data/examples/smartos_package/spec/remove_spec.rb +1 -1
- data/examples/smartos_package/spec/upgrade_spec.rb +1 -1
- data/examples/solaris_package/spec/install_spec.rb +1 -1
- data/examples/solaris_package/spec/remove_spec.rb +1 -1
- data/examples/state_attrs/spec/default_spec.rb +2 -2
- data/examples/step_into/spec/default_spec.rb +5 -2
- data/examples/stub_command/spec/default_spec.rb +1 -1
- data/examples/stub_data_bag/spec/default_spec.rb +1 -1
- data/examples/stub_data_bag_item/spec/default_spec.rb +1 -1
- data/examples/stub_search/spec/default_spec.rb +1 -1
- data/examples/subscribes/spec/chained_spec.rb +1 -1
- data/examples/subscribes/spec/default_spec.rb +1 -1
- data/examples/subscribes/spec/delayed_spec.rb +1 -1
- data/examples/subscribes/spec/immediately_spec.rb +1 -1
- data/examples/subversion/spec/checkout_spec.rb +1 -1
- data/examples/subversion/spec/export_spec.rb +1 -1
- data/examples/subversion/spec/force_export_spec.rb +1 -1
- data/examples/subversion/spec/sync_spec.rb +1 -1
- data/examples/template/spec/create_if_missing_spec.rb +1 -1
- data/examples/template/spec/create_spec.rb +1 -1
- data/examples/template/spec/delete_spec.rb +1 -1
- data/examples/template/spec/touch_spec.rb +1 -1
- data/examples/use_inline_resources/spec/default_spec.rb +4 -1
- data/examples/user/spec/create_spec.rb +1 -1
- data/examples/user/spec/lock_spec.rb +1 -1
- data/examples/user/spec/manage_spec.rb +1 -1
- data/examples/user/spec/modify_spec.rb +1 -1
- data/examples/user/spec/remove_spec.rb +1 -1
- data/examples/user/spec/unlock_spec.rb +1 -1
- data/examples/yum_package/spec/install_spec.rb +1 -1
- data/examples/yum_package/spec/purge_spec.rb +1 -1
- data/examples/yum_package/spec/remove_spec.rb +1 -1
- data/examples/yum_package/spec/upgrade_spec.rb +1 -1
- data/features/batch.feature +0 -3
- data/features/powershell_script.feature +0 -3
- data/features/render_file.feature +1 -6
- data/features/server.feature +0 -3
- data/features/smartos_package.feature +0 -4
- data/features/solaris_package.feature +0 -4
- data/features/state_attrs.feature +0 -4
- data/features/support/env.rb +0 -7
- data/gemfiles/{chef-11.12.0.gemfile → chef-11.16.0.gemfile} +1 -1
- data/gemfiles/chef-12.0.0.alpha.gemfile +5 -0
- data/lib/chefspec.rb +46 -14
- data/lib/chefspec/api.rb +0 -2
- data/lib/chefspec/api/apt_package.rb +1 -1
- data/lib/chefspec/api/batch.rb +1 -1
- data/lib/chefspec/api/chef_gem.rb +1 -1
- data/lib/chefspec/api/cookbook_file.rb +1 -1
- data/lib/chefspec/api/cron.rb +1 -1
- data/lib/chefspec/api/deploy.rb +1 -1
- data/lib/chefspec/api/directory.rb +1 -1
- data/lib/chefspec/api/dpkg_package.rb +1 -1
- data/lib/chefspec/api/easy_install_package.rb +1 -1
- data/lib/chefspec/api/env.rb +1 -1
- data/lib/chefspec/api/erl_call.rb +1 -1
- data/lib/chefspec/api/execute.rb +1 -1
- data/lib/chefspec/api/file.rb +1 -1
- data/lib/chefspec/api/freebsd_package.rb +1 -1
- data/lib/chefspec/api/gem_package.rb +1 -1
- data/lib/chefspec/api/git.rb +1 -1
- data/lib/chefspec/api/group.rb +1 -1
- data/lib/chefspec/api/http_request.rb +1 -1
- data/lib/chefspec/api/ifconfig.rb +1 -1
- data/lib/chefspec/api/ips_package.rb +1 -1
- data/lib/chefspec/api/link.rb +1 -1
- data/lib/chefspec/api/log.rb +1 -1
- data/lib/chefspec/api/macports_package.rb +1 -1
- data/lib/chefspec/api/mdadm.rb +1 -1
- data/lib/chefspec/api/mount.rb +1 -1
- data/lib/chefspec/api/ohai.rb +2 -2
- data/lib/chefspec/api/package.rb +1 -1
- data/lib/chefspec/api/pacman_package.rb +1 -1
- data/lib/chefspec/api/portage_package.rb +1 -1
- data/lib/chefspec/api/powershell_script.rb +1 -1
- data/lib/chefspec/api/registry_key.rb +1 -1
- data/lib/chefspec/api/remote_directory.rb +4 -4
- data/lib/chefspec/api/remote_file.rb +1 -1
- data/lib/chefspec/api/route.rb +1 -1
- data/lib/chefspec/api/rpm_package.rb +1 -1
- data/lib/chefspec/api/ruby_block.rb +1 -1
- data/lib/chefspec/api/script.rb +6 -6
- data/lib/chefspec/api/service.rb +1 -1
- data/lib/chefspec/api/smartos_package.rb +1 -1
- data/lib/chefspec/api/solaris_package.rb +1 -1
- data/lib/chefspec/api/subversion.rb +1 -1
- data/lib/chefspec/api/template.rb +1 -1
- data/lib/chefspec/api/user.rb +1 -1
- data/lib/chefspec/api/yum_package.rb +1 -1
- data/lib/chefspec/coverage/filters.rb +3 -0
- data/lib/chefspec/deprecations.rb +19 -123
- data/lib/chefspec/macros.rb +2 -2
- data/lib/chefspec/matchers/render_file_matcher.rb +2 -2
- data/lib/chefspec/matchers/resource_matcher.rb +1 -1
- data/lib/chefspec/matchers/state_attrs_matcher.rb +1 -1
- data/lib/chefspec/server.rb +4 -361
- data/lib/chefspec/server_methods.rb +175 -0
- data/lib/chefspec/server_runner.rb +86 -0
- data/lib/chefspec/{runner.rb → solo_runner.rb} +92 -43
- data/lib/chefspec/version.rb +1 -1
- data/spec/unit/{runner_spec.rb → solo_runner_spec.rb} +31 -25
- metadata +13 -10
data/lib/chefspec/api/service.rb
CHANGED
data/lib/chefspec/api/user.rb
CHANGED
@@ -16,6 +16,7 @@ module ChefSpec
|
|
16
16
|
#
|
17
17
|
class RegexpFilter < Filter
|
18
18
|
def matches?(resource)
|
19
|
+
return true if resource.source_line.nil?
|
19
20
|
@filter =~ resource.source_line
|
20
21
|
end
|
21
22
|
end
|
@@ -39,6 +40,7 @@ module ChefSpec
|
|
39
40
|
#
|
40
41
|
class BlockFilter < Filter
|
41
42
|
def matches?(resource)
|
43
|
+
return true if resource.source_line.nil?
|
42
44
|
@filter.call(resource)
|
43
45
|
end
|
44
46
|
end
|
@@ -68,6 +70,7 @@ module ChefSpec
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def matches?(resource)
|
73
|
+
return true if resource.source_line.nil?
|
71
74
|
resource.source_line =~ /cookbooks\/(?!#{@metadatas.join('|')})/
|
72
75
|
end
|
73
76
|
end
|
@@ -14,141 +14,37 @@ module Kernel
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
module ChefSpec
|
18
|
-
# @deprecated {ChefSpec::ChefRunner} is deprecated. Please use
|
19
|
-
# {ChefSpec::Runner} instead.
|
20
|
-
class ChefRunner
|
21
|
-
def self.new(*args, &block)
|
22
|
-
deprecated '`ChefSpec::ChefRunner` is deprecated. Please use' \
|
23
|
-
' `ChefSpec::Runner` instead.'
|
24
|
-
|
25
|
-
ChefSpec::Runner.new(*args, &block)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
17
|
module ChefSpec
|
31
18
|
class Runner
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
' automatically evaluated by default. Please use `stub_command` to' \
|
38
|
-
' stub shell guards.'
|
39
|
-
end
|
40
|
-
|
41
|
-
if args.first.has_key?(:actually_run_shell_guards)
|
42
|
-
deprecated 'The `:actually_run_shell_guards` option is deprecated.' \
|
43
|
-
' Shell commands must be stubbed using `stub_command`.'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
existing_initialize(*args, &block)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module ChefSpec::API
|
53
|
-
#
|
54
|
-
# @todo Remove in v4.0.0
|
55
|
-
#
|
56
|
-
module DeprecatedMatchers
|
57
|
-
def be_owned_by(user, group)
|
58
|
-
deprecated "The `be_owned_by` matcher is deprecated. Please use:" \
|
59
|
-
"\n\n" \
|
60
|
-
" expect(resource.owner).to eq('#{user}')\n" \
|
61
|
-
" expect(resource.group).to eq('#{group}')" \
|
62
|
-
"\n\n" \
|
63
|
-
"instead"
|
64
|
-
raise ChefSpec::NoConversionError.new('be_owned_by')
|
65
|
-
end
|
19
|
+
# @deprecated {ChefSpec.define_runner_method} is deprecated. Please
|
20
|
+
# use {ChefSpec.define_runner_method} instead.
|
21
|
+
def self.define_runner_method(resource_name)
|
22
|
+
deprecated "`ChefSpec.define_runner_method' is deprecated. " \
|
23
|
+
"Please use `ChefSpec.define_runner_method' instead."
|
66
24
|
|
67
|
-
|
68
|
-
deprecated "The `create_file_with_content` matcher is deprecated." \
|
69
|
-
" Please use `render_file(#{path.inspect})" \
|
70
|
-
".with_content(#{content.inspect})` instead."
|
71
|
-
ChefSpec::Matchers::RenderFileMatcher.new(path).with_content(content)
|
25
|
+
ChefSpec.define_matcher(resource_name)
|
72
26
|
end
|
73
27
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
".with(version: #{version.inspect})` instead."
|
80
|
-
ChefSpec::Matchers::ResourceMatcher.new(type, :install, package)
|
81
|
-
.with(version: version)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
[:bash, :csh, :perl, :python, :ruby, :script].each do |type|
|
86
|
-
matcher_name = "execute_#{type}_script".to_sym
|
87
|
-
define_method(matcher_name) do |name|
|
88
|
-
deprecated "The `#{matcher_name}` matcher is deprecated." \
|
89
|
-
" Please use `run_#{type}(#{name.inspect})` instead."
|
90
|
-
ChefSpec::Matchers::ResourceMatcher.new(type, :run, name)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def log(message)
|
95
|
-
deprecated "The `log` matcher is deprcated. Please use" \
|
96
|
-
" `write_log(#{message.inspect}) instead."
|
97
|
-
ChefSpec::Matchers::ResourceMatcher.new(:log, :write, message)
|
98
|
-
end
|
99
|
-
|
100
|
-
def set_service_to_start_on_boot(service)
|
101
|
-
deprecated "The `set_service_to_start_on_boot` matcher is" \
|
102
|
-
" deprecated. Please use `enable_service(#{service.inspect})`" \
|
103
|
-
" instead."
|
104
|
-
ChefSpec::Matchers::ResourceMatcher.new(:service, :enable, service)
|
105
|
-
end
|
106
|
-
|
107
|
-
def set_service_to_not_start_on_boot(service)
|
108
|
-
deprecated "The `set_service_to_not_start_on_boot` matcher is" \
|
109
|
-
" deprecated. Please use `enable_service(#{service.inspect})`" \
|
110
|
-
" with a negating argument instead."
|
111
|
-
raise ChefSpec::NoConversionError.new('set_service_to_start_on_boot')
|
112
|
-
end
|
113
|
-
|
114
|
-
def execute_ruby_block(name)
|
115
|
-
deprecated "The `execute_ruby_block` matcher is deprecated. Please" \
|
116
|
-
" use `run_ruby_block(#{name.inspect})` instead."
|
117
|
-
ChefSpec::Matchers::ResourceMatcher.new(:ruby_block, :run, name)
|
118
|
-
end
|
28
|
+
# @deprecated {ChefSpec::Runner.new} is deprecated. Please use
|
29
|
+
# {ChefSpec::SoloRunner} or {ChefSpec::ServerRunner} instead.
|
30
|
+
def self.new(*args, &block)
|
31
|
+
deprecated "`ChefSpec::Runner' is deprecated. Please use" \
|
32
|
+
" `ChefSpec::SoloRunner' or `ChefSpec::ServerRunner' instead."
|
119
33
|
|
120
|
-
|
121
|
-
deprecated "The `execute_command` matcher is deprecated. Please" \
|
122
|
-
" use `run_execute(#{command.inspect})` instead."
|
123
|
-
ChefSpec::Matchers::ResourceMatcher.new(:execute, :run, command)
|
34
|
+
ChefSpec::SoloRuner.new(*args, &block)
|
124
35
|
end
|
125
36
|
end
|
126
|
-
end
|
127
37
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
" `notify(#{resource.inspect}).to(#{action.to_sym.inspect})`" \
|
135
|
-
" instead."
|
136
|
-
new_notify(resource).to(action.to_sym)
|
137
|
-
else
|
138
|
-
new_notify(resource)
|
139
|
-
end
|
38
|
+
class Server
|
39
|
+
def self.method_missing(m, *args, &block)
|
40
|
+
deprecated "`ChefSpec::Server.#{m}' is deprecated. There is no longer" \
|
41
|
+
" a global Chef Server instance. Please use a ChefSpec::ServerRunner" \
|
42
|
+
" instead. More documentation can be found in the ChefSpec README."
|
43
|
+
raise NoConversionError
|
140
44
|
end
|
141
45
|
end
|
142
46
|
end
|
143
47
|
|
144
48
|
module ChefSpec::Error
|
145
|
-
class NoConversionError < ChefSpecError
|
146
|
-
def initialize(matcher)
|
147
|
-
message = "I cannot convert `#{matcher}` to use a new matcher format!" \
|
148
|
-
" Please see the ChefSpec documentation and CHANGELOG for details" \
|
149
|
-
" on converting this matcher. Sorry :("
|
150
|
-
|
151
|
-
super(message)
|
152
|
-
end
|
153
|
-
end
|
49
|
+
class NoConversionError < ChefSpecError; end
|
154
50
|
end
|
data/lib/chefspec/macros.rb
CHANGED
@@ -34,8 +34,8 @@ module ChefSpec
|
|
34
34
|
#
|
35
35
|
# The value of +described_recipe+ is "my_cookbook::my_recipe".
|
36
36
|
#
|
37
|
-
# @example Using +described_recipe+ in the +ChefSpec::
|
38
|
-
# let(:chef_run) { ChefSpec::
|
37
|
+
# @example Using +described_recipe+ in the +ChefSpec::SoloRunner+
|
38
|
+
# let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
|
39
39
|
#
|
40
40
|
#
|
41
41
|
# @return [String]
|
@@ -80,7 +80,7 @@ module ChefSpec::Matchers
|
|
80
80
|
#
|
81
81
|
# @param [Chef::Resource] resource
|
82
82
|
#
|
83
|
-
# @return [
|
83
|
+
# @return [true, false]
|
84
84
|
#
|
85
85
|
def has_create_action?
|
86
86
|
[:create, :create_if_missing].any? { |action| resource.performed_action?(action) }
|
@@ -91,7 +91,7 @@ module ChefSpec::Matchers
|
|
91
91
|
#
|
92
92
|
# @param [Chef::Resource] resource
|
93
93
|
#
|
94
|
-
# @return [
|
94
|
+
# @return [true, false]
|
95
95
|
#
|
96
96
|
def matches_content?
|
97
97
|
return true if @expected_content.nil?
|
@@ -153,7 +153,7 @@ module ChefSpec::Matchers
|
|
153
153
|
# Find the resource in the Chef run by the given class name and
|
154
154
|
# resource identity/name.
|
155
155
|
#
|
156
|
-
# @see ChefSpec::
|
156
|
+
# @see ChefSpec::SoloRunner#find_resource
|
157
157
|
#
|
158
158
|
# @return [Chef::Resource, nil]
|
159
159
|
#
|
data/lib/chefspec/server.rb
CHANGED
@@ -1,361 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'chef/cookbook_loader'
|
8
|
-
require 'chef/cookbook_uploader'
|
9
|
-
|
10
|
-
class Chef::CookbookUploader
|
11
|
-
#
|
12
|
-
# Don't validate uploaded cookbooks. Validating a cookbook takes *forever*
|
13
|
-
# to complete. It's just not worth it...
|
14
|
-
#
|
15
|
-
def validate_cookbooks
|
16
|
-
# noop
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class ChefSpec::Runner
|
21
|
-
alias_method :old_initialize, :initialize
|
22
|
-
|
23
|
-
#
|
24
|
-
# Override the existing initialize method, setting the appropriate
|
25
|
-
# configuration to use a real Chef Server instead.
|
26
|
-
#
|
27
|
-
# @see ChefSpec::Runner#initialize
|
28
|
-
#
|
29
|
-
def initialize(options = {}, &block)
|
30
|
-
old_initialize(options, &block)
|
31
|
-
|
32
|
-
Chef::Config[:client_key] = ChefSpec::Server.client_key
|
33
|
-
Chef::Config[:client_name] = 'chefspec'
|
34
|
-
Chef::Config[:node_name] = 'chefspec'
|
35
|
-
Chef::Config[:file_cache_path] = Dir.mktmpdir
|
36
|
-
Chef::Config[:solo] = false
|
37
|
-
|
38
|
-
upload_cookbooks!
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
#
|
44
|
-
# Upload the cookbooks to the Chef Server.
|
45
|
-
#
|
46
|
-
def upload_cookbooks!
|
47
|
-
loader = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
|
48
|
-
loader.load_cookbooks
|
49
|
-
|
50
|
-
uploader = Chef::CookbookUploader.new(loader.cookbooks, loader.cookbook_paths)
|
51
|
-
uploader.upload_cookbooks
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module ChefSpec
|
56
|
-
class Server
|
57
|
-
#
|
58
|
-
# Delegate all methods to the singleton instance.
|
59
|
-
#
|
60
|
-
def self.method_missing(m, *args, &block)
|
61
|
-
instance.send(m, *args, &block)
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# RSpec 3 checks +respond_to?+ for some odd reason.
|
66
|
-
#
|
67
|
-
def self.respond_to_missing?(m, include_private = false)
|
68
|
-
instance.respond_to?(m, include_private) || super
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# @macro entity
|
73
|
-
# @method create_$1(name, data = {})
|
74
|
-
# Create a new $1 on the Chef Server
|
75
|
-
#
|
76
|
-
# @param [String] name
|
77
|
-
# the name of the $1
|
78
|
-
# @param [Hash] data
|
79
|
-
# the list of data to load
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# @method $1(name)
|
83
|
-
# Find a $1 at the given name
|
84
|
-
#
|
85
|
-
# @param [String] name
|
86
|
-
# the name of the $1
|
87
|
-
#
|
88
|
-
# @return [$2, nil]
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# @method $3
|
92
|
-
# The list of $1 on the Chef Server
|
93
|
-
#
|
94
|
-
# @return [Array<Hash>]
|
95
|
-
# all the $1 on the Chef Server
|
96
|
-
#
|
97
|
-
#
|
98
|
-
# @method has_$1?(name)
|
99
|
-
# Determine if the Chef Server has the given $1
|
100
|
-
#
|
101
|
-
# @param [String] name
|
102
|
-
# the name of the $1 to find
|
103
|
-
#
|
104
|
-
# @return [Boolean]
|
105
|
-
#
|
106
|
-
def self.entity(method, klass, key)
|
107
|
-
class_eval <<-EOH, __FILE__, __LINE__ + 1
|
108
|
-
def create_#{method}(name, data = {})
|
109
|
-
# Automatically set the "name" if no explicit one was given
|
110
|
-
data[:name] ||= name
|
111
|
-
|
112
|
-
# Convert it to JSON
|
113
|
-
data = JSON.fast_generate(data)
|
114
|
-
|
115
|
-
load_data(name, '#{key}', data)
|
116
|
-
end
|
117
|
-
|
118
|
-
def #{method}(name)
|
119
|
-
data = get('#{key}', name)
|
120
|
-
json = JSON.parse(data)
|
121
|
-
|
122
|
-
if #{klass}.respond_to?(:json_create)
|
123
|
-
#{klass}.json_create(json)
|
124
|
-
else
|
125
|
-
#{klass}.new(json)
|
126
|
-
end
|
127
|
-
rescue ChefZero::DataStore::DataNotFoundError
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
|
131
|
-
def #{key}
|
132
|
-
get('#{key}')
|
133
|
-
end
|
134
|
-
|
135
|
-
def has_#{method}?(name)
|
136
|
-
!get('#{key}', name).nil?
|
137
|
-
rescue ChefZero::DataStore::DataNotFoundError
|
138
|
-
false
|
139
|
-
end
|
140
|
-
EOH
|
141
|
-
end
|
142
|
-
|
143
|
-
entity :client, Chef::Client, 'clients'
|
144
|
-
entity :data_bag, Chef::DataBag, 'data'
|
145
|
-
entity :environment, Chef::Environment, 'environments'
|
146
|
-
entity :node, Chef::Node, 'nodes'
|
147
|
-
entity :role, Chef::Role, 'roles'
|
148
|
-
|
149
|
-
include Singleton
|
150
|
-
|
151
|
-
attr_reader :server
|
152
|
-
|
153
|
-
#
|
154
|
-
# Create a new instance of the +ChefSpec::Server+ singleton. This method
|
155
|
-
# also starts the Chef Zero server in the background.
|
156
|
-
#
|
157
|
-
def initialize
|
158
|
-
@server = ChefZero::Server.new(
|
159
|
-
# Set the log level from RSpec, defaulting to warn
|
160
|
-
log_level: RSpec.configuration.log_level || :warn,
|
161
|
-
|
162
|
-
# Set a random port so ChefSpec may be run in multiple jobs
|
163
|
-
port: port,
|
164
|
-
)
|
165
|
-
end
|
166
|
-
|
167
|
-
#
|
168
|
-
# Create a new data_bag on the Chef Server. This overrides the method
|
169
|
-
# created by {entity}
|
170
|
-
#
|
171
|
-
# @param [String] name
|
172
|
-
# the name of the data bag
|
173
|
-
# @param [Hash] data
|
174
|
-
# the data to load into the data bag
|
175
|
-
#
|
176
|
-
def create_data_bag(name, data = {})
|
177
|
-
load_data(name, 'data', data)
|
178
|
-
end
|
179
|
-
|
180
|
-
#
|
181
|
-
# Create a new node on the Chef Server. This overrides the method created
|
182
|
-
# by {entity}, permitting users to pass a raw +Chef::Node+ object in
|
183
|
-
# addition to a hash.
|
184
|
-
#
|
185
|
-
# @example Create a node from a hash
|
186
|
-
#
|
187
|
-
# create_node('bacon', attribute: 'value')
|
188
|
-
#
|
189
|
-
# @example Create a node from a +Chef::Node+ object
|
190
|
-
#
|
191
|
-
# node = stub_node('bacon', platform: 'ubuntu', version: '12.04')
|
192
|
-
# create_node(node)
|
193
|
-
#
|
194
|
-
# @param [String, Chef::Node] object
|
195
|
-
# the object to create; this can be the name of the node, or an actual
|
196
|
-
# +Chef::Node+ object
|
197
|
-
# @param [Hash] data
|
198
|
-
# the list of data to populate the node with; this is ignored if an
|
199
|
-
# actual node object is given
|
200
|
-
#
|
201
|
-
def create_node(object, data = {})
|
202
|
-
if object.is_a?(Chef::Node)
|
203
|
-
name = object.name
|
204
|
-
data = object.to_json
|
205
|
-
else
|
206
|
-
name = object.to_s
|
207
|
-
data[:name] ||= name
|
208
|
-
data = JSON.fast_generate(data)
|
209
|
-
end
|
210
|
-
|
211
|
-
load_data(name, 'nodes', data)
|
212
|
-
end
|
213
|
-
|
214
|
-
#
|
215
|
-
# The path to the insecure Chef Zero private key on disk. Because Chef
|
216
|
-
# requires the path to a file instead of the contents of the key (why),
|
217
|
-
# this method dynamically writes the +ChefZero::PRIVATE_KEY+ to disk and
|
218
|
-
# then returns that path.
|
219
|
-
#
|
220
|
-
# @return [String]
|
221
|
-
# the path to the client key on disk
|
222
|
-
#
|
223
|
-
def client_key
|
224
|
-
@client_key ||= begin
|
225
|
-
path = File.join(cache_dir, 'client.pem')
|
226
|
-
File.open(path, 'w') { |f| f.write(ChefZero::PRIVATE_KEY) }
|
227
|
-
path
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
#
|
232
|
-
# The URL where ChefZero is listening.
|
233
|
-
#
|
234
|
-
# @return [String]
|
235
|
-
#
|
236
|
-
def chef_server_url
|
237
|
-
@chef_server_url ||= File.join(@server.url)
|
238
|
-
end
|
239
|
-
|
240
|
-
#
|
241
|
-
# Start the Chef Zero server in the background, updating the +Chef::Config+
|
242
|
-
# with the proper +chef_server_url+.
|
243
|
-
#
|
244
|
-
def start!
|
245
|
-
unless @server.running?
|
246
|
-
@server.start_background
|
247
|
-
Chef::Config[:chef_server_url] = chef_server_url
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
#
|
252
|
-
# Clear the contents of the server (used between examples)
|
253
|
-
#
|
254
|
-
def reset!
|
255
|
-
@server.clear_data
|
256
|
-
end
|
257
|
-
|
258
|
-
#
|
259
|
-
# Stop the Chef Zero server, if it is running. This method also runs any
|
260
|
-
# cleanup hooks, such as clearing the cache directories.
|
261
|
-
#
|
262
|
-
def stop!
|
263
|
-
@server.stop if @server.running?
|
264
|
-
FileUtils.rm_rf(cache_dir)
|
265
|
-
end
|
266
|
-
|
267
|
-
private
|
268
|
-
|
269
|
-
#
|
270
|
-
# The directory where any cache information (such as private keys) should
|
271
|
-
# be stored. This cache is destroyed at the end of the run.
|
272
|
-
#
|
273
|
-
# @return [String]
|
274
|
-
# the path to the cache directory on disk
|
275
|
-
#
|
276
|
-
def cache_dir
|
277
|
-
@cache_dir ||= Dir.mktmpdir(['chefspec', 'cache'])
|
278
|
-
end
|
279
|
-
|
280
|
-
#
|
281
|
-
# Shortcut method for loading data into Chef Zero.
|
282
|
-
#
|
283
|
-
# @param [String] name
|
284
|
-
# the name or id of the item to load
|
285
|
-
# @param [String, Symbol] key
|
286
|
-
# the key to load
|
287
|
-
# @param [Hash] data
|
288
|
-
# the data for the object, which will be converted to JSON and uploaded
|
289
|
-
# to the server
|
290
|
-
#
|
291
|
-
def load_data(name, key, data = {})
|
292
|
-
@server.load_data({ key => { name => data } })
|
293
|
-
end
|
294
|
-
|
295
|
-
#
|
296
|
-
# Get the path to an item in the data store.
|
297
|
-
#
|
298
|
-
def get(*args)
|
299
|
-
# This is a real-life "what in the actual fuck!?". Since some engineers
|
300
|
-
# cannot seem to understand the importance of an unchanging public API,
|
301
|
-
# we have to implement crazy, outlandish checks like this.
|
302
|
-
#
|
303
|
-
# In the 2.0 series of Chef Zero, the DataStore did not prefix values.
|
304
|
-
# In the 2.1+ series, DataStore values are nested under
|
305
|
-
# +organizations/chef+, for some ridiciously reason.
|
306
|
-
#
|
307
|
-
# Oh, and for the record, there was no CHANGELOG entry or anything. They
|
308
|
-
# just decided it would be a good idea to change one of the main APIs in
|
309
|
-
# the system.
|
310
|
-
if ChefZero::VERSION.to_f == 2.0
|
311
|
-
get_without_prefix(*args)
|
312
|
-
else
|
313
|
-
get_with_prefix(*args)
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
# @see {get}
|
318
|
-
def get_without_prefix(*args)
|
319
|
-
if args.size == 1
|
320
|
-
@server.data_store.list(args)
|
321
|
-
else
|
322
|
-
@server.data_store.get(args)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
# @see {get}
|
327
|
-
def get_with_prefix(*args)
|
328
|
-
args.unshift('organizations', 'chef')
|
329
|
-
|
330
|
-
if args.size == 3
|
331
|
-
@server.data_store.list(args)
|
332
|
-
else
|
333
|
-
@server.data_store.get(args)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
#
|
338
|
-
# A randomly assigned, open port for run the Chef Zero server.
|
339
|
-
#
|
340
|
-
# @return [Fixnum]
|
341
|
-
#
|
342
|
-
def port
|
343
|
-
return @port if @port
|
344
|
-
|
345
|
-
@server = TCPServer.new('127.0.0.1', 0)
|
346
|
-
@port = @server.addr[1].to_i
|
347
|
-
@server.close
|
348
|
-
|
349
|
-
return @port
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
ChefSpec::Server.start!
|
355
|
-
|
356
|
-
RSpec.configure do |config|
|
357
|
-
config.before(:each) { ChefSpec::Server.reset! }
|
358
|
-
config.after(:each) { ChefSpec::Server.reset! }
|
359
|
-
end
|
360
|
-
|
361
|
-
at_exit { ChefSpec::Server.stop! }
|
1
|
+
# @todo Remove in v5.0.0
|
2
|
+
require_relative 'deprecations'
|
3
|
+
deprecated "require 'chefspec/server' is no longer required and " \
|
4
|
+
"will be removed in the next major release."
|