chefspec 7.2.1 → 7.3.0
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/.travis.yml +21 -13
- data/CHANGELOG.md +4 -0
- data/Gemfile +14 -10
- data/README.md +322 -1025
- data/README_old.md +1291 -0
- data/Rakefile +8 -3
- data/examples/apt_package/spec/install_spec.rb +1 -1
- data/examples/apt_package/spec/lock_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/unlock_spec.rb +1 -1
- data/examples/apt_package/spec/upgrade_spec.rb +1 -1
- data/examples/apt_repository/spec/add_spec.rb +1 -1
- data/examples/apt_repository/spec/remove_spec.rb +1 -1
- data/examples/apt_update/spec/periodic_spec.rb +1 -1
- data/examples/apt_update/spec/update_spec.rb +1 -1
- data/examples/attributes/spec/default_spec.rb +1 -1
- data/examples/batch/spec/run_spec.rb +1 -1
- data/examples/cab_package/spec/install_spec.rb +1 -1
- data/examples/cab_package/spec/remove_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/chocolatey_package/spec/install_spec.rb +1 -1
- data/examples/chocolatey_package/spec/remove_spec.rb +1 -1
- data/examples/chocolatey_package/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/core/recipes/default.rb +1 -0
- data/examples/core/spec/default_spec.rb +7 -0
- data/examples/core/spec/non_recipe_spec.rb +5 -0
- data/examples/cron/spec/create_spec.rb +1 -1
- data/examples/cron/spec/delete_spec.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/custom_resource/spec/default_spec.rb +1 -1
- data/examples/custom_resource_block/resources/default.rb +3 -0
- data/examples/custom_resource_block/spec/default_spec.rb +10 -0
- data/examples/directory/spec/create_spec.rb +1 -1
- data/examples/directory/spec/delete_spec.rb +1 -1
- data/examples/dnf_package/spec/install_spec.rb +1 -1
- data/examples/dnf_package/spec/purge_spec.rb +1 -1
- data/examples/dnf_package/spec/remove_spec.rb +1 -1
- data/examples/dnf_package/spec/upgrade_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/dsc_resource/spec/run_spec.rb +1 -1
- data/examples/dsc_script/spec/run_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/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/homebrew_package/spec/install_spec.rb +1 -1
- data/examples/homebrew_package/spec/purge_spec.rb +1 -1
- data/examples/homebrew_package/spec/remove_spec.rb +1 -1
- data/examples/homebrew_package/spec/upgrade_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/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/launchd/spec/create_if_missing_spec.rb +1 -1
- data/examples/launchd/spec/create_spec.rb +1 -1
- data/examples/launchd/spec/delete_spec.rb +1 -1
- data/examples/launchd/spec/disable_spec.rb +1 -1
- data/examples/launchd/spec/enable_spec.rb +1 -1
- data/examples/library_patch/libraries/default.rb +5 -0
- data/examples/library_patch/recipes/default.rb +1 -0
- data/examples/library_patch/spec/default_spec.rb +14 -0
- 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/msu_package/spec/install_spec.rb +1 -1
- data/examples/msu_package/spec/remove_spec.rb +1 -1
- data/examples/multiple_actions/spec/default_spec.rb +1 -1
- data/examples/multiple_actions/spec/reversed_spec.rb +1 -1
- data/examples/multiple_actions/spec/sequential_spec.rb +1 -1
- data/examples/multiple_run_action/spec/default_spec.rb +1 -1
- data/examples/nothing_matcher/spec/default_spec.rb +1 -1
- data/examples/notifications/spec/before_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/osx_profile/spec/install_spec.rb +1 -1
- data/examples/osx_profile/spec/remove_spec.rb +1 -1
- data/examples/package/spec/install_spec.rb +1 -1
- data/examples/package/spec/lock_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/unlock_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/paludis_package/spec/install_spec.rb +1 -1
- data/examples/paludis_package/spec/purge_spec.rb +1 -1
- data/examples/paludis_package/spec/remove_spec.rb +1 -1
- data/examples/paludis_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/reboot/spec/cancel_spec.rb +1 -1
- data/examples/reboot/spec/now_spec.rb +1 -1
- data/examples/reboot/spec/request_spec.rb +1 -1
- data/examples/recipe_block/metadata.rb +1 -0
- data/examples/recipe_block/spec/recipe_block_spec.rb +34 -0
- data/examples/recipe_block/templates/apache2.conf.erb +1 -0
- 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 +12 -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/create_spec.rb +1 -1
- data/examples/ruby_block/spec/run_spec.rb +1 -1
- data/examples/runner/recipes/default.rb +1 -0
- data/examples/runner/spec/default_spec.rb +11 -0
- 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_ksh_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 +1 -1
- data/examples/server/spec/data_bag_spec.rb +1 -1
- data/examples/server/spec/environment_spec.rb +1 -1
- data/examples/server/spec/exotic_port_spec.rb +1 -1
- data/examples/server/spec/node_spec.rb +4 -4
- data/examples/server/spec/render_with_cached_spec.rb +1 -1
- data/examples/server/spec/role_spec.rb +1 -1
- data/examples/server/spec/search_spec.rb +1 -1
- 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/solaris_package/spec/upgrade_spec.rb +1 -1
- data/examples/spec_attributes/attributes/default.rb +1 -0
- data/examples/spec_attributes/recipes/default.rb +5 -0
- data/examples/spec_attributes/spec/default_spec.rb +54 -0
- data/examples/spec_platform/recipes/default.rb +3 -0
- data/examples/spec_platform/spec/default_spec.rb +36 -0
- data/examples/spec_step_into/recipes/default.rb +3 -0
- data/examples/spec_step_into/resources/one.rb +3 -0
- data/examples/spec_step_into/resources/two.rb +3 -0
- data/examples/spec_step_into/spec/default_spec.rb +50 -0
- data/examples/state_attrs/spec/default_spec.rb +1 -1
- data/examples/step_into/spec/default_spec.rb +2 -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_node/spec/default_spec.rb +1 -1
- data/examples/stub_search/spec/block_spec.rb +1 -1
- data/examples/stub_search/spec/default_spec.rb +1 -1
- data/examples/stubs_for/resources/default.rb +20 -0
- data/examples/stubs_for/resources/old.rb +26 -0
- data/examples/stubs_for/spec/default_spec.rb +240 -0
- data/examples/subscribes/spec/before_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/systemd_unit/spec/create_spec.rb +1 -1
- data/examples/systemd_unit/spec/delete_spec.rb +1 -1
- data/examples/systemd_unit/spec/disable_spec.rb +1 -1
- data/examples/systemd_unit/spec/enable_spec.rb +1 -1
- data/examples/systemd_unit/spec/mask_spec.rb +1 -1
- data/examples/systemd_unit/spec/reload_or_restart_spec.rb +1 -1
- data/examples/systemd_unit/spec/reload_or_try_restart_spec.rb +1 -1
- data/examples/systemd_unit/spec/restart_spec.rb +1 -1
- data/examples/systemd_unit/spec/start_spec.rb +1 -1
- data/examples/systemd_unit/spec/stop_spec.rb +1 -1
- data/examples/systemd_unit/spec/try_restart_spec.rb +1 -1
- data/examples/systemd_unit/spec/unmask_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 +1 -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/windows_package/spec/install_spec.rb +1 -1
- data/examples/windows_package/spec/remove_spec.rb +1 -1
- data/examples/windows_service/spec/configure_startup_spec.rb +1 -1
- data/examples/windows_service/spec/disable_spec.rb +1 -1
- data/examples/windows_service/spec/enable_spec.rb +1 -1
- data/examples/windows_service/spec/reload_spec.rb +1 -1
- data/examples/windows_service/spec/restart_spec.rb +1 -1
- data/examples/windows_service/spec/start_spec.rb +1 -1
- data/examples/windows_service/spec/stop_spec.rb +1 -1
- data/examples/yum_package/spec/install_spec.rb +1 -1
- data/examples/yum_package/spec/lock_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/unlock_spec.rb +1 -1
- data/examples/yum_package/spec/upgrade_spec.rb +1 -1
- data/examples/yum_repository/spec/add_spec.rb +1 -1
- data/examples/yum_repository/spec/create_spec.rb +1 -1
- data/examples/yum_repository/spec/delete_spec.rb +1 -1
- data/examples/yum_repository/spec/makecache_spec.rb +1 -1
- data/examples/yum_repository/spec/remove_spec.rb +1 -1
- data/examples/zypper_package/spec/install_spec.rb +1 -1
- data/examples/zypper_package/spec/lock_spec.rb +1 -1
- data/examples/zypper_package/spec/purge_spec.rb +1 -1
- data/examples/zypper_package/spec/remove_spec.rb +1 -1
- data/examples/zypper_package/spec/unlock_spec.rb +1 -1
- data/examples/zypper_package/spec/upgrade_spec.rb +1 -1
- data/lib/chefspec.rb +1 -1
- data/lib/chefspec/api.rb +33 -14
- data/lib/chefspec/api/core.rb +195 -0
- data/lib/chefspec/api/described.rb +55 -0
- data/lib/chefspec/api/do_nothing.rb +24 -19
- data/lib/chefspec/api/include_recipe.rb +26 -21
- data/lib/chefspec/api/link.rb +26 -21
- data/lib/chefspec/api/notifications.rb +38 -33
- data/lib/chefspec/api/reboot.rb +11 -6
- data/lib/chefspec/api/render_file.rb +35 -30
- data/lib/chefspec/api/state_attrs.rb +28 -23
- data/lib/chefspec/api/stubs.rb +183 -0
- data/lib/chefspec/api/stubs_for.rb +134 -0
- data/lib/chefspec/api/subscriptions.rb +35 -30
- data/lib/chefspec/api/user.rb +222 -217
- data/lib/chefspec/berkshelf.rb +1 -1
- data/lib/chefspec/deprecations.rb +2 -11
- data/lib/chefspec/errors.rb +1 -0
- data/lib/chefspec/extensions.rb +4 -1
- data/lib/chefspec/extensions/chef/client.rb +3 -4
- data/lib/chefspec/extensions/chef/conditional.rb +3 -2
- data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +25 -28
- data/lib/chefspec/extensions/chef/cookbook_loader.rb +13 -0
- data/lib/chefspec/extensions/chef/cookbook_uploader.rb +3 -2
- data/lib/chefspec/extensions/chef/data_query.rb +5 -8
- data/lib/chefspec/extensions/chef/lwrp_base.rb +17 -21
- data/lib/chefspec/extensions/chef/provider.rb +36 -0
- data/lib/chefspec/extensions/chef/resource.rb +51 -4
- data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +13 -16
- data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +64 -0
- data/lib/chefspec/matchers/render_file_matcher.rb +36 -26
- data/lib/chefspec/matchers/resource_matcher.rb +1 -1
- data/lib/chefspec/rspec.rb +3 -8
- data/lib/chefspec/runner.rb +8 -0
- data/lib/chefspec/server_methods.rb +1 -1
- data/lib/chefspec/server_runner.rb +13 -9
- data/lib/chefspec/solo_runner.rb +136 -32
- data/lib/chefspec/version.rb +1 -1
- data/spec/unit/deprecations_spec.rb +1 -26
- data/spec/unit/macros_spec.rb +14 -14
- data/spec/unit/matchers/render_file_matcher_spec.rb +8 -1
- data/spec/unit/solo_runner_spec.rb +3 -3
- data/templates/errors/may_need_to_specify_platform.erb +1 -1
- data/templates/errors/shell_out_not_stubbed.erb +10 -0
- metadata +38 -4
- data/lib/chefspec/macros.rb +0 -222
data/lib/chefspec/version.rb
CHANGED
|
@@ -27,31 +27,6 @@ describe ChefSpec::Runner do
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
end
|
|
30
|
-
|
|
31
|
-
describe '#new' do
|
|
32
|
-
before do
|
|
33
|
-
allow(ChefSpec::SoloRunner).to receive(:new)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'prints a deprecation' do
|
|
37
|
-
expect(ChefSpec::Runner).to receive(:deprecated)
|
|
38
|
-
.with("`ChefSpec::Runner' is deprecated. Please use" \
|
|
39
|
-
" `ChefSpec::SoloRunner' or `ChefSpec::ServerRunner' instead.")
|
|
40
|
-
ChefSpec::Runner.new
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'calls SoloRunner#new with no args' do
|
|
44
|
-
expect(ChefSpec::SoloRunner).to receive(:new).with(no_args()).once
|
|
45
|
-
ChefSpec::Runner.new
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'calls SoloRunner#new with args' do
|
|
49
|
-
args = [ 'args' ]
|
|
50
|
-
expect(ChefSpec::SoloRunner).to receive(:new).with(*args).once
|
|
51
|
-
ChefSpec::Runner.new(*args)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
30
|
end
|
|
56
31
|
|
|
57
32
|
describe ChefSpec::Server do
|
|
@@ -62,7 +37,7 @@ describe ChefSpec::Server do
|
|
|
62
37
|
it 'prints a deprecation for any method called' do
|
|
63
38
|
expect(ChefSpec::Server).to receive(:deprecated)
|
|
64
39
|
.with("`ChefSpec::Server.any_method' is deprecated. There is no longer" \
|
|
65
|
-
" a global Chef Server instance. Please use a ChefSpec::
|
|
40
|
+
" a global Chef Server instance. Please use a ChefSpec::SoloRunner" \
|
|
66
41
|
" instead. More documentation can be found in the ChefSpec README."
|
|
67
42
|
)
|
|
68
43
|
expect {
|
data/spec/unit/macros_spec.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe ChefSpec::
|
|
3
|
+
describe ChefSpec::API::Stubs do
|
|
4
4
|
describe '#stub_command' do
|
|
5
5
|
let(:command_stub) { double('command') }
|
|
6
6
|
|
|
7
7
|
it 'adds the command to the command registry' do
|
|
8
8
|
allow(ChefSpec::Stubs::CommandStub).to receive(:new).and_return(command_stub)
|
|
9
|
-
|
|
9
|
+
stub_command('echo "hello"')
|
|
10
10
|
|
|
11
11
|
expect(ChefSpec::Stubs::CommandRegistry.stubs).to include(command_stub)
|
|
12
12
|
end
|
|
@@ -17,7 +17,7 @@ describe ChefSpec::Macros do
|
|
|
17
17
|
|
|
18
18
|
it 'adds the query to the search registry' do
|
|
19
19
|
allow(ChefSpec::Stubs::SearchStub).to receive(:new).and_return(search_stub)
|
|
20
|
-
|
|
20
|
+
stub_search(:node, '*:*')
|
|
21
21
|
|
|
22
22
|
expect(ChefSpec::Stubs::SearchRegistry.stubs).to include(search_stub)
|
|
23
23
|
end
|
|
@@ -28,7 +28,7 @@ describe ChefSpec::Macros do
|
|
|
28
28
|
|
|
29
29
|
it 'adds the query to the data_bag registry' do
|
|
30
30
|
allow(ChefSpec::Stubs::DataBagStub).to receive(:new).and_return(data_bag_stub)
|
|
31
|
-
|
|
31
|
+
stub_data_bag(:users)
|
|
32
32
|
|
|
33
33
|
expect(ChefSpec::Stubs::DataBagRegistry.stubs).to include(data_bag_stub)
|
|
34
34
|
end
|
|
@@ -39,7 +39,7 @@ describe ChefSpec::Macros do
|
|
|
39
39
|
|
|
40
40
|
it 'adds the query to the data_bag_item registry' do
|
|
41
41
|
allow(ChefSpec::Stubs::DataBagItemStub).to receive(:new).and_return(data_bag_item_stub)
|
|
42
|
-
|
|
42
|
+
stub_data_bag_item(:users, 'id')
|
|
43
43
|
|
|
44
44
|
expect(ChefSpec::Stubs::DataBagItemRegistry.stubs).to include(data_bag_item_stub)
|
|
45
45
|
end
|
|
@@ -47,43 +47,43 @@ describe ChefSpec::Macros do
|
|
|
47
47
|
|
|
48
48
|
describe '#stub_node' do
|
|
49
49
|
it 'returns a Chef::Node' do
|
|
50
|
-
expect(
|
|
50
|
+
expect(stub_node).to be_a(Chef::Node)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it 'defaults the node name to `node.example`' do
|
|
54
|
-
node =
|
|
54
|
+
node = stub_node
|
|
55
55
|
expect(node.name).to eq('node.example')
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it 'sets the node name when given' do
|
|
59
|
-
node =
|
|
59
|
+
node = stub_node('example.com')
|
|
60
60
|
expect(node.name).to eq('example.com')
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it 'sets the automatic attributes' do
|
|
64
|
-
node =
|
|
64
|
+
node = stub_node
|
|
65
65
|
expect(node.automatic).to eq(Fauxhai.mock.data)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it 'sets the automatic attributes with ohai overrides' do
|
|
69
|
-
node =
|
|
69
|
+
node = stub_node('node.example', ohai: { ipaddress: '1.2.3.4' })
|
|
70
70
|
expect(node['ipaddress']).to eq('1.2.3.4')
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it 'sets the automatic attributes for a specific platform and version' do
|
|
74
|
-
node =
|
|
75
|
-
expect(node.automatic).to eq(Fauxhai.mock(platform: 'ubuntu', version: '
|
|
74
|
+
node = stub_node('node.example', platform: 'ubuntu', version: '18.04')
|
|
75
|
+
expect(node.automatic).to eq(Fauxhai.mock(platform: 'ubuntu', version: '18.04').data)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it 'sets the automatic attributes from a JSON data path' do
|
|
79
79
|
allow(File).to receive(:exist?).with('/path/to/json').and_return(true)
|
|
80
80
|
allow(File).to receive(:read).with('/path/to/json').and_return('{ "ipaddress": "1.2.3.4" }')
|
|
81
|
-
node =
|
|
81
|
+
node = stub_node('node.example', path: '/path/to/json')
|
|
82
82
|
expect(node['ipaddress']).to eq('1.2.3.4')
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it 'yields a block' do
|
|
86
|
-
expect { |block|
|
|
86
|
+
expect { |block| stub_node(&block) }.to yield_with_args(Chef::Node)
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
end
|
|
@@ -12,7 +12,7 @@ describe ChefSpec::Matchers::RenderFileMatcher do
|
|
|
12
12
|
expect(
|
|
13
13
|
subject.with_content do |content|
|
|
14
14
|
'Does not raise ArgumentError'
|
|
15
|
-
end.expected_content.call
|
|
15
|
+
end.expected_content.first.call
|
|
16
16
|
).to eq('Does not raise ArgumentError')
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -38,6 +38,13 @@ describe ChefSpec::Matchers::RenderFileMatcher do
|
|
|
38
38
|
subject.matches?(chef_run)
|
|
39
39
|
expect(subject.description).to eq(%Q(render file "#{path}"))
|
|
40
40
|
end
|
|
41
|
+
|
|
42
|
+
it 'has the right value when with_content is chained' do
|
|
43
|
+
subject.matches?(chef_run)
|
|
44
|
+
expect(
|
|
45
|
+
subject.with_content('foo').with_content('bar').description
|
|
46
|
+
).to eq(%Q(render file "#{path}" with content "foo" with content "bar"))
|
|
47
|
+
end
|
|
41
48
|
end
|
|
42
49
|
|
|
43
50
|
context 'when the file is correct' do
|
|
@@ -47,7 +47,7 @@ describe ChefSpec::SoloRunner do
|
|
|
47
47
|
it 'defaults the cookbook_path to the calling spec when using windows paths' do
|
|
48
48
|
runner = described_class.new
|
|
49
49
|
windows_path = runner.instance_exec(windows_caller_stack) { |callstack|
|
|
50
|
-
calling_cookbook_path(callstack)
|
|
50
|
+
calling_cookbook_path({}, callstack)
|
|
51
51
|
}
|
|
52
52
|
# There's got to be a better way to do this the File.expand_path returns
|
|
53
53
|
# something like /home/user/repos/chefspec/C:/cookbooks" which is less
|
|
@@ -93,12 +93,12 @@ describe ChefSpec::SoloRunner do
|
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
context 'fauxhai attributes' do
|
|
96
|
-
let(:hash) { described_class.new(platform: 'ubuntu', version: '
|
|
96
|
+
let(:hash) { described_class.new(platform: 'ubuntu', version: '18.04').node.to_hash }
|
|
97
97
|
|
|
98
98
|
it 'sets the attributes from fauxhai' do
|
|
99
99
|
expect(hash['os']).to eq('linux')
|
|
100
100
|
expect(hash['languages']['ruby']['ruby_bin']).to eq('/usr/local/bin/ruby')
|
|
101
|
-
expect(hash['os_version']).to match(/4.
|
|
101
|
+
expect(hash['os_version']).to match(/4.15.0-.*-.*/) # avoid failing when fauxhai data changes
|
|
102
102
|
expect(hash['fqdn']).to eq('fauxhai.local')
|
|
103
103
|
expect(hash['domain']).to eq('local')
|
|
104
104
|
expect(hash['ipaddress']).to eq('10.0.0.2')
|
|
@@ -13,7 +13,7 @@ options.
|
|
|
13
13
|
You can specify the platform and version you would like ChefSpec to act like
|
|
14
14
|
by specifying the platform and version like so:
|
|
15
15
|
|
|
16
|
-
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '
|
|
16
|
+
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '18.04')
|
|
17
17
|
|
|
18
18
|
You can read more information in ChefSpec's README or the Fauxhai project:
|
|
19
19
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Executing a real shell_out in <%= @resource %> is not allowed:
|
|
2
|
+
|
|
3
|
+
shell_out(<%= @args.inspect[1..-2] %>)
|
|
4
|
+
|
|
5
|
+
You can stub this with:
|
|
6
|
+
|
|
7
|
+
stubs_for_<%= @type %>(<%= @resource.to_s.inspect %>) do |<%= @type %>|
|
|
8
|
+
allow(<%= @type %>).to receive_shell_out(<%= @args.inspect[1..-2] %>)
|
|
9
|
+
end
|
|
10
|
+
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chefspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Crump
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2018-
|
|
12
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: chef
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- ISSUES.md
|
|
72
72
|
- LICENSE
|
|
73
73
|
- README.md
|
|
74
|
+
- README_old.md
|
|
74
75
|
- Rakefile
|
|
75
76
|
- chefspec.gemspec
|
|
76
77
|
- examples/apt_package/recipes/install.rb
|
|
@@ -140,6 +141,9 @@ files:
|
|
|
140
141
|
- examples/cookbook_file/spec/create_spec.rb
|
|
141
142
|
- examples/cookbook_file/spec/delete_spec.rb
|
|
142
143
|
- examples/cookbook_file/spec/touch_spec.rb
|
|
144
|
+
- examples/core/recipes/default.rb
|
|
145
|
+
- examples/core/spec/default_spec.rb
|
|
146
|
+
- examples/core/spec/non_recipe_spec.rb
|
|
143
147
|
- examples/cron/recipes/create.rb
|
|
144
148
|
- examples/cron/recipes/delete.rb
|
|
145
149
|
- examples/cron/spec/create_spec.rb
|
|
@@ -154,6 +158,8 @@ files:
|
|
|
154
158
|
- examples/custom_resource/recipes/default.rb
|
|
155
159
|
- examples/custom_resource/resources/custom_resource.rb
|
|
156
160
|
- examples/custom_resource/spec/default_spec.rb
|
|
161
|
+
- examples/custom_resource_block/resources/default.rb
|
|
162
|
+
- examples/custom_resource_block/spec/default_spec.rb
|
|
157
163
|
- examples/directory/recipes/create.rb
|
|
158
164
|
- examples/directory/recipes/delete.rb
|
|
159
165
|
- examples/directory/spec/create_spec.rb
|
|
@@ -282,6 +288,9 @@ files:
|
|
|
282
288
|
- examples/launchd/spec/delete_spec.rb
|
|
283
289
|
- examples/launchd/spec/disable_spec.rb
|
|
284
290
|
- examples/launchd/spec/enable_spec.rb
|
|
291
|
+
- examples/library_patch/libraries/default.rb
|
|
292
|
+
- examples/library_patch/recipes/default.rb
|
|
293
|
+
- examples/library_patch/spec/default_spec.rb
|
|
285
294
|
- examples/link/recipes/create.rb
|
|
286
295
|
- examples/link/recipes/delete.rb
|
|
287
296
|
- examples/link/recipes/link_to.rb
|
|
@@ -398,6 +407,9 @@ files:
|
|
|
398
407
|
- examples/reboot/spec/cancel_spec.rb
|
|
399
408
|
- examples/reboot/spec/now_spec.rb
|
|
400
409
|
- examples/reboot/spec/request_spec.rb
|
|
410
|
+
- examples/recipe_block/metadata.rb
|
|
411
|
+
- examples/recipe_block/spec/recipe_block_spec.rb
|
|
412
|
+
- examples/recipe_block/templates/apache2.conf.erb
|
|
401
413
|
- examples/registry_key/recipes/create.rb
|
|
402
414
|
- examples/registry_key/recipes/create_if_missing.rb
|
|
403
415
|
- examples/registry_key/recipes/delete.rb
|
|
@@ -447,6 +459,8 @@ files:
|
|
|
447
459
|
- examples/ruby_block/recipes/run.rb
|
|
448
460
|
- examples/ruby_block/spec/create_spec.rb
|
|
449
461
|
- examples/ruby_block/spec/run_spec.rb
|
|
462
|
+
- examples/runner/recipes/default.rb
|
|
463
|
+
- examples/runner/spec/default_spec.rb
|
|
450
464
|
- examples/script/recipes/run_bash.rb
|
|
451
465
|
- examples/script/recipes/run_csh.rb
|
|
452
466
|
- examples/script/recipes/run_ksh.rb
|
|
@@ -500,6 +514,15 @@ files:
|
|
|
500
514
|
- examples/solaris_package/spec/install_spec.rb
|
|
501
515
|
- examples/solaris_package/spec/remove_spec.rb
|
|
502
516
|
- examples/solaris_package/spec/upgrade_spec.rb
|
|
517
|
+
- examples/spec_attributes/attributes/default.rb
|
|
518
|
+
- examples/spec_attributes/recipes/default.rb
|
|
519
|
+
- examples/spec_attributes/spec/default_spec.rb
|
|
520
|
+
- examples/spec_platform/recipes/default.rb
|
|
521
|
+
- examples/spec_platform/spec/default_spec.rb
|
|
522
|
+
- examples/spec_step_into/recipes/default.rb
|
|
523
|
+
- examples/spec_step_into/resources/one.rb
|
|
524
|
+
- examples/spec_step_into/resources/two.rb
|
|
525
|
+
- examples/spec_step_into/spec/default_spec.rb
|
|
503
526
|
- examples/state_attrs/providers/lwrp.rb
|
|
504
527
|
- examples/state_attrs/recipes/default.rb
|
|
505
528
|
- examples/state_attrs/resources/lwrp.rb
|
|
@@ -523,6 +546,9 @@ files:
|
|
|
523
546
|
- examples/stub_search/recipes/default.rb
|
|
524
547
|
- examples/stub_search/spec/block_spec.rb
|
|
525
548
|
- examples/stub_search/spec/default_spec.rb
|
|
549
|
+
- examples/stubs_for/resources/default.rb
|
|
550
|
+
- examples/stubs_for/resources/old.rb
|
|
551
|
+
- examples/stubs_for/spec/default_spec.rb
|
|
526
552
|
- examples/subscribes/recipes/before.rb
|
|
527
553
|
- examples/subscribes/recipes/chained.rb
|
|
528
554
|
- examples/subscribes/recipes/default.rb
|
|
@@ -643,6 +669,8 @@ files:
|
|
|
643
669
|
- examples/zypper_package/spec/upgrade_spec.rb
|
|
644
670
|
- lib/chefspec.rb
|
|
645
671
|
- lib/chefspec/api.rb
|
|
672
|
+
- lib/chefspec/api/core.rb
|
|
673
|
+
- lib/chefspec/api/described.rb
|
|
646
674
|
- lib/chefspec/api/do_nothing.rb
|
|
647
675
|
- lib/chefspec/api/include_recipe.rb
|
|
648
676
|
- lib/chefspec/api/link.rb
|
|
@@ -650,6 +678,8 @@ files:
|
|
|
650
678
|
- lib/chefspec/api/reboot.rb
|
|
651
679
|
- lib/chefspec/api/render_file.rb
|
|
652
680
|
- lib/chefspec/api/state_attrs.rb
|
|
681
|
+
- lib/chefspec/api/stubs.rb
|
|
682
|
+
- lib/chefspec/api/stubs_for.rb
|
|
653
683
|
- lib/chefspec/api/subscriptions.rb
|
|
654
684
|
- lib/chefspec/api/user.rb
|
|
655
685
|
- lib/chefspec/berkshelf.rb
|
|
@@ -663,16 +693,18 @@ files:
|
|
|
663
693
|
- lib/chefspec/extensions/chef/client.rb
|
|
664
694
|
- lib/chefspec/extensions/chef/conditional.rb
|
|
665
695
|
- lib/chefspec/extensions/chef/cookbook/gem_installer.rb
|
|
696
|
+
- lib/chefspec/extensions/chef/cookbook_loader.rb
|
|
666
697
|
- lib/chefspec/extensions/chef/cookbook_uploader.rb
|
|
667
698
|
- lib/chefspec/extensions/chef/data_query.rb
|
|
668
699
|
- lib/chefspec/extensions/chef/lwrp_base.rb
|
|
700
|
+
- lib/chefspec/extensions/chef/provider.rb
|
|
669
701
|
- lib/chefspec/extensions/chef/resource.rb
|
|
670
702
|
- lib/chefspec/extensions/chef/resource/freebsd_package.rb
|
|
703
|
+
- lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb
|
|
671
704
|
- lib/chefspec/extensions/chef/securable.rb
|
|
672
705
|
- lib/chefspec/file_cache_path_proxy.rb
|
|
673
706
|
- lib/chefspec/formatter.rb
|
|
674
707
|
- lib/chefspec/librarian.rb
|
|
675
|
-
- lib/chefspec/macros.rb
|
|
676
708
|
- lib/chefspec/matchers.rb
|
|
677
709
|
- lib/chefspec/matchers/do_nothing_matcher.rb
|
|
678
710
|
- lib/chefspec/matchers/include_recipe_matcher.rb
|
|
@@ -686,6 +718,7 @@ files:
|
|
|
686
718
|
- lib/chefspec/policyfile.rb
|
|
687
719
|
- lib/chefspec/renderer.rb
|
|
688
720
|
- lib/chefspec/rspec.rb
|
|
721
|
+
- lib/chefspec/runner.rb
|
|
689
722
|
- lib/chefspec/server.rb
|
|
690
723
|
- lib/chefspec/server_methods.rb
|
|
691
724
|
- lib/chefspec/server_runner.rb
|
|
@@ -742,6 +775,7 @@ files:
|
|
|
742
775
|
- templates/errors/may_need_to_specify_platform.erb
|
|
743
776
|
- templates/errors/no_conversion_error.erb
|
|
744
777
|
- templates/errors/not_stubbed.erb
|
|
778
|
+
- templates/errors/shell_out_not_stubbed.erb
|
|
745
779
|
- templates/errors/template_not_found.erb
|
|
746
780
|
homepage: https://sethvargo.github.io/chefspec/
|
|
747
781
|
licenses:
|
|
@@ -763,7 +797,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
763
797
|
version: '0'
|
|
764
798
|
requirements: []
|
|
765
799
|
rubyforge_project:
|
|
766
|
-
rubygems_version: 2.7.
|
|
800
|
+
rubygems_version: 2.7.7
|
|
767
801
|
signing_key:
|
|
768
802
|
specification_version: 4
|
|
769
803
|
summary: Write RSpec examples and generate coverage reports for Chef recipes!
|
data/lib/chefspec/macros.rb
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
module ChefSpec
|
|
2
|
-
module Macros
|
|
3
|
-
extend self
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# The name of the currently running cookbook spec. Given the top-level
|
|
7
|
-
# +describe+ block is of the format:
|
|
8
|
-
#
|
|
9
|
-
# describe 'my_cookbook::my_recipe' do
|
|
10
|
-
# # ...
|
|
11
|
-
# end
|
|
12
|
-
#
|
|
13
|
-
# The value of +described_cookbook+ is "my_cookbook".
|
|
14
|
-
#
|
|
15
|
-
# @example Using +described_cookbook+ in a context block
|
|
16
|
-
# context "#{described_recipe} installs foo" do
|
|
17
|
-
# # ...
|
|
18
|
-
# end
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# @return [String]
|
|
22
|
-
#
|
|
23
|
-
def described_cookbook
|
|
24
|
-
described_recipe.split('::').first
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
# The name of the currently running recipe spec. Given the top-level
|
|
29
|
-
# +describe+ block is of the format:
|
|
30
|
-
#
|
|
31
|
-
# describe 'my_cookbook::my_recipe' do
|
|
32
|
-
# # ...
|
|
33
|
-
# end
|
|
34
|
-
#
|
|
35
|
-
# The value of +described_recipe+ is "my_cookbook::my_recipe".
|
|
36
|
-
#
|
|
37
|
-
# @example Using +described_recipe+ in the +ChefSpec::SoloRunner+
|
|
38
|
-
# let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
# @return [String]
|
|
42
|
-
#
|
|
43
|
-
def described_recipe
|
|
44
|
-
scope = self.is_a?(Class) ? self : self.class
|
|
45
|
-
|
|
46
|
-
metahash = scope.metadata
|
|
47
|
-
while metahash.has_key?(:parent_example_group)
|
|
48
|
-
metahash = metahash[:parent_example_group]
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
metahash[:description].to_s
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
# Stub a shell command to return a particular value without
|
|
56
|
-
# shelling out to the system.
|
|
57
|
-
#
|
|
58
|
-
# @example stubbing a command to return true
|
|
59
|
-
# stub_command('test -f /tmp/bacon').and_return(true)
|
|
60
|
-
#
|
|
61
|
-
# @example stubbing a block that is evaluated at runtime
|
|
62
|
-
# stub_command('test -f /tmp/bacon') { MyClass.check? }
|
|
63
|
-
#
|
|
64
|
-
# @example stubbing a command that matches a pattern
|
|
65
|
-
# stub_command(/test \-f/).and_return(true)
|
|
66
|
-
#
|
|
67
|
-
# @example stubbing a command that raises an exception
|
|
68
|
-
# stub_command('test -f /tmp/bacon').and_raise(SomeException)
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
# @param [String, Regexp] command
|
|
72
|
-
# the command to stub
|
|
73
|
-
#
|
|
74
|
-
# @return [ChefSpec::CommandStub]
|
|
75
|
-
#
|
|
76
|
-
def stub_command(command, &block)
|
|
77
|
-
Stubs::CommandRegistry.register(Stubs::CommandStub.new(command, &block))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
#
|
|
81
|
-
# Stub a Chef call to load a data_bag.
|
|
82
|
-
#
|
|
83
|
-
# @example stubbing a data_bag to return an empty Array
|
|
84
|
-
# stub_data_bag('users').and_return([])
|
|
85
|
-
#
|
|
86
|
-
# @example stubbing a data_bag with a block that is evaluated at runtime
|
|
87
|
-
# stub_data_bag('users') { JSON.parse(File.read('fixtures/data_bag.json')) }
|
|
88
|
-
#
|
|
89
|
-
# @example stubbing a data_bag to return an Array of Hashes
|
|
90
|
-
# stub_data_bag('users').and_return([
|
|
91
|
-
# { id: 'bacon', comment: 'delicious' },
|
|
92
|
-
# { id: 'ham', comment: 'also good' }
|
|
93
|
-
# ])
|
|
94
|
-
#
|
|
95
|
-
# @example stubbing a data_bag to raise an exception
|
|
96
|
-
# stub_data_bag('users').and_raise(Chef::Exceptions::PrivateKeyMissing)
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
# @param [String, Symbol] bag
|
|
100
|
-
# the name of the data bag to stub
|
|
101
|
-
#
|
|
102
|
-
# @return [ChefSpec::DataBagStub]
|
|
103
|
-
#
|
|
104
|
-
def stub_data_bag(bag, &block)
|
|
105
|
-
Stubs::DataBagRegistry.register(Stubs::DataBagStub.new(bag, &block))
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
#
|
|
109
|
-
# Stub a Chef data_bag call.
|
|
110
|
-
#
|
|
111
|
-
# @example stubbing a data_bag_item to return a Hash of data
|
|
112
|
-
# stub_data_bag_item('users', 'svargo').and_return({
|
|
113
|
-
# id: 'svargo',
|
|
114
|
-
# name: 'Seth Vargo'
|
|
115
|
-
# })
|
|
116
|
-
#
|
|
117
|
-
# @example stubbing a data_bag_item with a block that is evaluated at runtime
|
|
118
|
-
# stub_data_bag_item('users', 'svargo') { JSON.parse(File.read('fixtures/data_bag_item.json')) }
|
|
119
|
-
#
|
|
120
|
-
# @example stubbing a data_bag_item to raise an exception
|
|
121
|
-
# stub_data_bag('users', 'svargo').and_raise(Chef::Exceptions::PrivateKeyMissing)
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
-
# @param [String, Symbol] bag
|
|
125
|
-
# the name of the data bag to find the item in
|
|
126
|
-
# @param [String] id
|
|
127
|
-
# the id of the data bag item to stub
|
|
128
|
-
#
|
|
129
|
-
# @return [ChefSpec::DataBagItemStub]
|
|
130
|
-
#
|
|
131
|
-
def stub_data_bag_item(bag, id, &block)
|
|
132
|
-
Stubs::DataBagItemRegistry.register(Stubs::DataBagItemStub.new(bag, id, &block))
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
#
|
|
136
|
-
# Creates a fake Chef::Node for use in testing.
|
|
137
|
-
#
|
|
138
|
-
# @example mocking a simple node
|
|
139
|
-
# stub_node('mynode.example')
|
|
140
|
-
#
|
|
141
|
-
# @example mocking a specific platform and version
|
|
142
|
-
# stub_node('mynode.example', platform: 'ubuntu', version: '16.04')
|
|
143
|
-
#
|
|
144
|
-
# @example overriding a specific ohai attribute
|
|
145
|
-
# stub_node('mynode.example', ohai: { ipaddress: '1.2.3.4' })
|
|
146
|
-
#
|
|
147
|
-
# @example stubbing a node based on a JSON fixture
|
|
148
|
-
# stub_node('mynode.example', path: File.join('fixtures', 'nodes', 'default.json'))
|
|
149
|
-
#
|
|
150
|
-
# @example setting specific attributes
|
|
151
|
-
# stub_node('mynode.example') do |node|
|
|
152
|
-
# node.default['attribute']['thing'] = 'value'
|
|
153
|
-
# end
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# @param [String] name
|
|
157
|
-
# the name of the node
|
|
158
|
-
# @param [Hash] options
|
|
159
|
-
# the list of options for the node
|
|
160
|
-
#
|
|
161
|
-
# @option options [Symbol] :platform
|
|
162
|
-
# the platform to mock
|
|
163
|
-
# @option options [Symbol] :version
|
|
164
|
-
# the version of the platform to mock
|
|
165
|
-
# @option options [Symbol] :path
|
|
166
|
-
# filepath to a JSON file to pull a node from
|
|
167
|
-
# @option options [Hash] :ohai
|
|
168
|
-
# a Hash of Ohai attributes to mock on the node
|
|
169
|
-
#
|
|
170
|
-
# @return [Chef::Node]
|
|
171
|
-
#
|
|
172
|
-
def stub_node(*args, &block)
|
|
173
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
174
|
-
name = args.first || 'node.example'
|
|
175
|
-
|
|
176
|
-
fauxhai = Fauxhai.mock(options).data
|
|
177
|
-
fauxhai = fauxhai.merge(options[:ohai] || {})
|
|
178
|
-
fauxhai = Mash.new(fauxhai)
|
|
179
|
-
|
|
180
|
-
node = Chef::Node.new
|
|
181
|
-
node.name(name)
|
|
182
|
-
node.automatic_attrs = fauxhai
|
|
183
|
-
node.instance_eval(&block) if block_given?
|
|
184
|
-
node
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
#
|
|
188
|
-
# Stub a Chef search to return pre-defined data. When providing a value,
|
|
189
|
-
# the value is automatically mashified (to the best of ChefSpec's abilities)
|
|
190
|
-
# to ease in use.
|
|
191
|
-
#
|
|
192
|
-
# @example stubbing a search to return nothing
|
|
193
|
-
# stub_search(:node)
|
|
194
|
-
#
|
|
195
|
-
# @example stubbing a search with a query
|
|
196
|
-
# stub_search(:node, 'name:*')
|
|
197
|
-
#
|
|
198
|
-
# @example stubbing a search with a query as a regex
|
|
199
|
-
# stub_search(:node, /name:(.+)/)
|
|
200
|
-
#
|
|
201
|
-
# @example stubbing a search with a block that is evaluated at runtime
|
|
202
|
-
# stub_search(:node) { JSON.parse(File.read('fixtures/nodes.json')) }
|
|
203
|
-
#
|
|
204
|
-
# @example stubbing a search to return a fixed value
|
|
205
|
-
# stub_search(:node).and_return([ { a: 'b' } ])
|
|
206
|
-
#
|
|
207
|
-
# @example stubbing a search to raise an exception
|
|
208
|
-
# stub_search(:node).and_raise(Chef::Exceptions::PrivateKeyMissing)
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
# @param [String, Symbol] type
|
|
212
|
-
# the type to search to stub
|
|
213
|
-
# @param [String, Symbol, nil] query
|
|
214
|
-
# the query to stub
|
|
215
|
-
#
|
|
216
|
-
# @return [ChefSpec::SearchStub]
|
|
217
|
-
#
|
|
218
|
-
def stub_search(type, query = '*:*', &block)
|
|
219
|
-
Stubs::SearchRegistry.register(Stubs::SearchStub.new(type, query, &block))
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|