chefspec 7.2.1 → 7.3.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 +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
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'chef/run_context/cookbook_compiler'
|
2
|
+
|
3
|
+
Chef::RunContext::CookbookCompiler.prepend(Module.new do
|
4
|
+
# List of compile phases as of Chef 14:
|
5
|
+
# compile_libraries
|
6
|
+
# compile_ohai_plugins
|
7
|
+
# compile_attributes
|
8
|
+
# compile_lwrps
|
9
|
+
# compile_resource_definitions
|
10
|
+
# compile_recipes
|
11
|
+
|
12
|
+
#
|
13
|
+
# Compile phases that should only ever run once, globally.
|
14
|
+
#
|
15
|
+
|
16
|
+
def load_libraries_from_cookbook(cookbook)
|
17
|
+
return super unless $CHEFSPEC_MODE
|
18
|
+
$CHEFSPEC_LIBRARY_PRELOAD ||= {}
|
19
|
+
# Already loaded this once.
|
20
|
+
return if $CHEFSPEC_LIBRARY_PRELOAD[cookbook]
|
21
|
+
$CHEFSPEC_LIBRARY_PRELOAD[cookbook] = true
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_lwrps_from_cookbook(cookbook)
|
26
|
+
return super unless $CHEFSPEC_MODE
|
27
|
+
$CHEFSPEC_LWRP_PRELOAD ||= {}
|
28
|
+
# Already loaded this once.
|
29
|
+
return if $CHEFSPEC_LWRP_PRELOAD[cookbook]
|
30
|
+
$CHEFSPEC_LWRP_PRELOAD[cookbook] = true
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_resource_definitions_from_cookbook(cookbook)
|
35
|
+
return super unless $CHEFSPEC_MODE
|
36
|
+
$CHEFSPEC_DEFINITION_PRELOAD ||= {}
|
37
|
+
# Already loaded this once.
|
38
|
+
return if $CHEFSPEC_DEFINITION_PRELOAD[cookbook]
|
39
|
+
$CHEFSPEC_DEFINITION_PRELOAD[cookbook] = true
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Compile phases that should not run during preload
|
45
|
+
#
|
46
|
+
|
47
|
+
def compile_ohai_plugins
|
48
|
+
return super unless $CHEFSPEC_MODE
|
49
|
+
return if $CHEFSPEC_PRELOAD
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
53
|
+
def compile_attributes
|
54
|
+
return super unless $CHEFSPEC_MODE
|
55
|
+
return if $CHEFSPEC_PRELOAD
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
def compile_recipes
|
60
|
+
return super unless $CHEFSPEC_MODE
|
61
|
+
return if $CHEFSPEC_PRELOAD
|
62
|
+
super
|
63
|
+
end
|
64
|
+
end)
|
@@ -3,6 +3,7 @@ module ChefSpec::Matchers
|
|
3
3
|
attr_reader :expected_content
|
4
4
|
def initialize(path)
|
5
5
|
@path = path
|
6
|
+
@expected_content = []
|
6
7
|
end
|
7
8
|
|
8
9
|
def matches?(runner)
|
@@ -20,9 +21,9 @@ module ChefSpec::Matchers
|
|
20
21
|
if expected_content && block
|
21
22
|
raise ArgumentError, "Cannot specify expected content and a block!"
|
22
23
|
elsif expected_content
|
23
|
-
@expected_content
|
24
|
+
@expected_content << expected_content
|
24
25
|
elsif block_given?
|
25
|
-
@expected_content
|
26
|
+
@expected_content << block
|
26
27
|
else
|
27
28
|
raise ArgumentError, "Must specify expected content or a block!"
|
28
29
|
end
|
@@ -32,11 +33,11 @@ module ChefSpec::Matchers
|
|
32
33
|
|
33
34
|
def description
|
34
35
|
message = %Q{render file "#{@path}"}
|
35
|
-
|
36
|
-
if
|
36
|
+
@expected_content.each do |expected|
|
37
|
+
if expected.to_s.include?("\n")
|
37
38
|
message << " with content <suppressed>"
|
38
39
|
else
|
39
|
-
message << " with content #{
|
40
|
+
message << " with content #{expected.inspect}"
|
40
41
|
end
|
41
42
|
end
|
42
43
|
message
|
@@ -44,7 +45,7 @@ module ChefSpec::Matchers
|
|
44
45
|
|
45
46
|
def failure_message
|
46
47
|
message = %Q{expected Chef run to render "#{@path}"}
|
47
|
-
|
48
|
+
unless @expected_content.empty?
|
48
49
|
message << " matching:"
|
49
50
|
message << "\n\n"
|
50
51
|
message << expected_content_message
|
@@ -59,7 +60,7 @@ module ChefSpec::Matchers
|
|
59
60
|
|
60
61
|
def failure_message_when_negated
|
61
62
|
message = %Q{expected file "#{@path}"}
|
62
|
-
|
63
|
+
unless @expected_content.empty?
|
63
64
|
message << " matching:"
|
64
65
|
message << "\n\n"
|
65
66
|
message << expected_content_message
|
@@ -72,13 +73,16 @@ module ChefSpec::Matchers
|
|
72
73
|
private
|
73
74
|
|
74
75
|
def expected_content_message
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
messages = @expected_content.collect do |expected|
|
77
|
+
if RSpec::Matchers.is_a_matcher?(expected) && expected.respond_to?(:description)
|
78
|
+
expected.description
|
79
|
+
elsif expected.is_a?(Proc)
|
80
|
+
"(the result of a proc)"
|
81
|
+
else
|
82
|
+
expected.to_s
|
83
|
+
end
|
81
84
|
end
|
85
|
+
messages.join("\n\n")
|
82
86
|
end
|
83
87
|
|
84
88
|
def resource
|
@@ -106,25 +110,31 @@ module ChefSpec::Matchers
|
|
106
110
|
# @return [true, false]
|
107
111
|
#
|
108
112
|
def matches_content?
|
109
|
-
return true if @expected_content.
|
113
|
+
return true if @expected_content.empty?
|
110
114
|
|
111
115
|
@actual_content = ChefSpec::Renderer.new(@runner, resource).content
|
112
116
|
|
113
117
|
return false if @actual_content.nil?
|
114
118
|
|
115
|
-
if
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
# Knock out matches that pass. When we're done, we pass if the list is
|
120
|
+
# empty. Otherwise, @expected_content is the list of matchers that
|
121
|
+
# failed
|
122
|
+
@expected_content.delete_if do |expected|
|
123
|
+
if expected.is_a?(Regexp)
|
124
|
+
@actual_content =~ expected
|
125
|
+
elsif RSpec::Matchers.is_a_matcher?(expected)
|
126
|
+
expected.matches?(@actual_content)
|
127
|
+
elsif expected.is_a?(Proc)
|
128
|
+
expected.call(@actual_content)
|
129
|
+
# Weird RSpecish, but that block will return false for a negated check,
|
130
|
+
# so we always return true. The block will raise an exception if the
|
131
|
+
# assertion fails.
|
132
|
+
true
|
133
|
+
else
|
134
|
+
@actual_content.include?(expected)
|
135
|
+
end
|
127
136
|
end
|
137
|
+
@expected_content.empty?
|
128
138
|
end
|
129
139
|
end
|
130
140
|
end
|
data/lib/chefspec/rspec.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
config.after(:each) do
|
6
|
-
ChefSpec::Stubs::CommandRegistry.reset!
|
7
|
-
ChefSpec::Stubs::DataBagRegistry.reset!
|
8
|
-
ChefSpec::Stubs::DataBagItemRegistry.reset!
|
9
|
-
ChefSpec::Stubs::SearchRegistry.reset!
|
2
|
+
unless ENV['CHEFSPEC_NO_INCLUDE']
|
3
|
+
config.include(ChefSpec::API)
|
10
4
|
end
|
11
5
|
|
12
6
|
config.add_setting :berkshelf_options, default: {}
|
13
7
|
config.add_setting :file_cache_path
|
8
|
+
config.add_setting :cookbook_root
|
14
9
|
config.add_setting :cookbook_path
|
15
10
|
config.add_setting :role_path
|
16
11
|
config.add_setting :environment_path
|
@@ -118,7 +118,7 @@ module ChefSpec
|
|
118
118
|
#
|
119
119
|
# @example Create a node from a +Chef::Node+ object
|
120
120
|
#
|
121
|
-
# node = stub_node('bacon', platform: 'ubuntu', version: '
|
121
|
+
# node = stub_node('bacon', platform: 'ubuntu', version: '18.04')
|
122
122
|
# create_node(node)
|
123
123
|
#
|
124
124
|
# @param [String, Chef::Node] object
|
@@ -23,15 +23,6 @@ module ChefSpec
|
|
23
23
|
# our yielding.
|
24
24
|
super(options, &nil)
|
25
25
|
|
26
|
-
Chef::Config[:client_key] = client_key
|
27
|
-
Chef::Config[:client_name] = 'chefspec'
|
28
|
-
Chef::Config[:node_name] = 'chefspec'
|
29
|
-
Chef::Config[:solo] = false
|
30
|
-
Chef::Config[:solo_legacy_mode] = false
|
31
|
-
|
32
|
-
Chef::Config[:chef_server_url] = server.url
|
33
|
-
Chef::Config[:http_retry_count] = 0
|
34
|
-
|
35
26
|
# Unlike the SoloRunner, the node AND server object are yielded for
|
36
27
|
# customization
|
37
28
|
yield node, self if block_given?
|
@@ -68,5 +59,18 @@ module ChefSpec
|
|
68
59
|
at_exit { FileUtils.rm_rf(tmp) }
|
69
60
|
path
|
70
61
|
end
|
62
|
+
|
63
|
+
# (see SoloRunner#apply_chef_config!)
|
64
|
+
def apply_chef_config!
|
65
|
+
super
|
66
|
+
Chef::Config[:client_key] = client_key
|
67
|
+
Chef::Config[:client_name] = 'chefspec'
|
68
|
+
Chef::Config[:node_name] = 'chefspec'
|
69
|
+
Chef::Config[:solo] = false
|
70
|
+
Chef::Config[:solo_legacy_mode] = false
|
71
|
+
|
72
|
+
Chef::Config[:chef_server_url] = server.url
|
73
|
+
Chef::Config[:http_retry_count] = 0
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
data/lib/chefspec/solo_runner.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'fauxhai'
|
2
2
|
require 'chef/client'
|
3
|
+
require 'chef/cookbook/metadata'
|
3
4
|
require 'chef/mash'
|
4
5
|
require 'chef/providers'
|
5
6
|
require 'chef/resources'
|
@@ -34,7 +35,7 @@ module ChefSpec
|
|
34
35
|
# ChefSpec::SoloRunner.new
|
35
36
|
#
|
36
37
|
# @example Specifying the platform and version
|
37
|
-
# ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '
|
38
|
+
# ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '18.04')
|
38
39
|
#
|
39
40
|
# @example Specifying the cookbook path
|
40
41
|
# ChefSpec::SoloRunner.new(cookbook_path: ['/cookbooks'])
|
@@ -63,26 +64,7 @@ module ChefSpec
|
|
63
64
|
#
|
64
65
|
def initialize(options = {})
|
65
66
|
@options = with_default_options(options)
|
66
|
-
|
67
|
-
Chef::Log.level = @options[:log_level]
|
68
|
-
|
69
|
-
Chef::Config.reset!
|
70
|
-
Chef::Config.formatters.clear
|
71
|
-
Chef::Config.add_formatter('chefspec')
|
72
|
-
Chef::Config[:cache_type] = 'Memory'
|
73
|
-
Chef::Config[:client_key] = nil
|
74
|
-
Chef::Config[:client_name] = nil
|
75
|
-
Chef::Config[:node_name] = nil
|
76
|
-
Chef::Config[:file_cache_path] = @options[:file_cache_path] || file_cache_path
|
77
|
-
Chef::Config[:cookbook_path] = Array(@options[:cookbook_path])
|
78
|
-
Chef::Config[:no_lazy_load] = true
|
79
|
-
Chef::Config[:role_path] = Array(@options[:role_path])
|
80
|
-
Chef::Config[:force_logger] = true
|
81
|
-
Chef::Config[:solo] = true
|
82
|
-
Chef::Config[:solo_legacy_mode] = true
|
83
|
-
Chef::Config[:use_policyfile] = false
|
84
|
-
Chef::Config[:environment_path] = @options[:environment_path]
|
85
|
-
|
67
|
+
apply_chef_config!
|
86
68
|
yield node if block_given?
|
87
69
|
end
|
88
70
|
|
@@ -105,6 +87,10 @@ module ChefSpec
|
|
105
87
|
# A reference to the calling Runner (for chaining purposes)
|
106
88
|
#
|
107
89
|
def converge(*recipe_names)
|
90
|
+
# Re-apply the Chef config before converging in case something else
|
91
|
+
# called Config.reset too.
|
92
|
+
apply_chef_config!
|
93
|
+
@converging = false
|
108
94
|
node.run_list.reset!
|
109
95
|
recipe_names.each { |recipe_name| node.run_list.add(recipe_name) }
|
110
96
|
|
@@ -113,6 +99,14 @@ module ChefSpec
|
|
113
99
|
# Expand the run_list
|
114
100
|
expand_run_list!
|
115
101
|
|
102
|
+
# Merge in provided node attributes. Default and override use the role_
|
103
|
+
# levels so they win over the relevant bits from cookbooks since otherwise
|
104
|
+
# they would not and that would be confusing.
|
105
|
+
node.attributes.role_default = Chef::Mixin::DeepMerge.merge(node.attributes.role_default, options[:default_attributes]) if options[:default_attributes]
|
106
|
+
node.attributes.normal = Chef::Mixin::DeepMerge.merge(node.attributes.normal, options[:normal_attributes]) if options[:normal_attributes]
|
107
|
+
node.attributes.role_override = Chef::Mixin::DeepMerge.merge(node.attributes.role_override, options[:override_attributes]) if options[:override_attributes]
|
108
|
+
node.attributes.automatic = Chef::Mixin::DeepMerge.merge(node.attributes.automatic, options[:automatic_attributes]) if options[:automatic_attributes]
|
109
|
+
|
116
110
|
# Setup the run_context, rescuing the exception that happens when a
|
117
111
|
# resource is not defined on a particular platform
|
118
112
|
begin
|
@@ -132,18 +126,53 @@ module ChefSpec
|
|
132
126
|
self
|
133
127
|
end
|
134
128
|
|
129
|
+
#
|
130
|
+
# Execute a block of recipe code.
|
131
|
+
#
|
132
|
+
# @param [Proc] block
|
133
|
+
# A block containing Chef recipe code
|
134
|
+
#
|
135
|
+
# @return [ChefSpec::SoloRunner]
|
136
|
+
#
|
137
|
+
def converge_block(&block)
|
138
|
+
converge do
|
139
|
+
recipe = Chef::Recipe.new(cookbook_name, '_test', run_context)
|
140
|
+
recipe.instance_exec(&block)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Run a static preload of the cookbook under test. This will load libraries
|
146
|
+
# and resources, but not attributes or recipes.
|
147
|
+
#
|
148
|
+
# @return [void]
|
149
|
+
#
|
150
|
+
def preload!
|
151
|
+
# Flag to disable preloading for situations where it doesn't make sense.
|
152
|
+
return if ENV['CHEFSPEC_NO_PRELOAD']
|
153
|
+
begin
|
154
|
+
old_preload = $CHEFSPEC_PRELOAD
|
155
|
+
$CHEFSPEC_PRELOAD = true
|
156
|
+
converge("recipe[#{cookbook_name}]")
|
157
|
+
node.run_list.reset!
|
158
|
+
ensure
|
159
|
+
$CHEFSPEC_PRELOAD = old_preload
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
135
163
|
#
|
136
164
|
# The +Chef::Node+ corresponding to this Runner.
|
137
165
|
#
|
138
166
|
# @return [Chef::Node]
|
139
167
|
#
|
140
168
|
def node
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
169
|
+
runner = self
|
170
|
+
@node ||= begin
|
171
|
+
apply_chef_config!
|
172
|
+
client.build_node.tap do |node|
|
173
|
+
node.define_singleton_method(:runner) { runner }
|
174
|
+
end
|
175
|
+
end
|
147
176
|
end
|
148
177
|
|
149
178
|
#
|
@@ -306,7 +335,8 @@ module ChefSpec
|
|
306
335
|
config = RSpec.configuration
|
307
336
|
|
308
337
|
{
|
309
|
-
|
338
|
+
cookbook_root: config.cookbook_root || calling_cookbook_root(options, caller),
|
339
|
+
cookbook_path: config.cookbook_path || calling_cookbook_path(options, caller),
|
310
340
|
role_path: config.role_path || default_role_path,
|
311
341
|
environment_path: config.environment_path || default_environment_path,
|
312
342
|
file_cache_path: config.file_cache_path,
|
@@ -318,21 +348,37 @@ module ChefSpec
|
|
318
348
|
end
|
319
349
|
|
320
350
|
#
|
321
|
-
# The inferred
|
351
|
+
# The inferred cookbook root from the calling spec.
|
322
352
|
#
|
353
|
+
# @param [Hash<Symbol, Object>] options
|
354
|
+
# initial runner options
|
323
355
|
# @param [Array<String>] kaller
|
324
356
|
# the calling trace
|
325
357
|
#
|
326
358
|
# @return [String]
|
327
359
|
#
|
328
|
-
def
|
329
|
-
calling_spec = kaller.find { |line| line =~ /\/spec/ }
|
360
|
+
def calling_cookbook_root(options, kaller)
|
361
|
+
calling_spec = options[:spec_declaration_locations] || kaller.find { |line| line =~ /\/spec/ }
|
330
362
|
raise Error::CookbookPathNotFound if calling_spec.nil?
|
331
363
|
|
332
364
|
bits = calling_spec.split(/:[0-9]/, 2).first.split(File::SEPARATOR)
|
333
365
|
spec_dir = bits.index('spec') || 0
|
334
366
|
|
335
|
-
File.
|
367
|
+
File.join(bits.slice(0, spec_dir))
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# The inferred path from the calling spec.
|
372
|
+
#
|
373
|
+
# @param [Hash<Symbol, Object>] options
|
374
|
+
# initial runner options
|
375
|
+
# @param [Array<String>] kaller
|
376
|
+
# the calling trace
|
377
|
+
#
|
378
|
+
# @return [String]
|
379
|
+
#
|
380
|
+
def calling_cookbook_path(options, kaller)
|
381
|
+
File.expand_path(File.join(calling_cookbook_root(options, kaller), '..'))
|
336
382
|
end
|
337
383
|
|
338
384
|
#
|
@@ -406,5 +452,63 @@ module ChefSpec
|
|
406
452
|
end
|
407
453
|
end
|
408
454
|
end
|
455
|
+
|
456
|
+
#
|
457
|
+
# Try to load the cookbook metadata for the cookbook under test.
|
458
|
+
#
|
459
|
+
# @return [Chef::Cookbook::Metadata]
|
460
|
+
#
|
461
|
+
def cookbook
|
462
|
+
@cookbook ||= Chef::Cookbook::Metadata.new.tap {|m| m.from_file("#{options[:cookbook_root]}/metadata.rb") }
|
463
|
+
end
|
464
|
+
|
465
|
+
#
|
466
|
+
# Try to figure out the name for the cookbook under test.
|
467
|
+
#
|
468
|
+
# @return [String]
|
469
|
+
#
|
470
|
+
def cookbook_name
|
471
|
+
# Try to figure out the name of this cookbook, pretending this block
|
472
|
+
# is in the name context as the cookbook under test.
|
473
|
+
begin
|
474
|
+
cookbook.name
|
475
|
+
rescue IOError
|
476
|
+
# Old cookbook, has no metadata, use the folder name I guess.
|
477
|
+
File.basename(options[:cookbook_root])
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
#
|
482
|
+
# Apply the required options to {Chef::Config}.
|
483
|
+
#
|
484
|
+
# @api private
|
485
|
+
# @return [void]
|
486
|
+
#
|
487
|
+
def apply_chef_config!
|
488
|
+
Chef::Log.level = @options[:log_level]
|
489
|
+
|
490
|
+
Chef::Config.reset!
|
491
|
+
Chef::Config.formatters.clear
|
492
|
+
Chef::Config.add_formatter('chefspec')
|
493
|
+
Chef::Config[:cache_type] = 'Memory'
|
494
|
+
Chef::Config[:client_key] = nil
|
495
|
+
Chef::Config[:client_name] = nil
|
496
|
+
Chef::Config[:node_name] = nil
|
497
|
+
Chef::Config[:file_cache_path] = @options[:file_cache_path] || file_cache_path
|
498
|
+
Chef::Config[:cookbook_path] = Array(@options[:cookbook_path])
|
499
|
+
# If the word cookbook is in the folder name, treat it as the path. Otherwise
|
500
|
+
# it's probably not a cookbook path and so we activate the gross hack mode.
|
501
|
+
if Chef::Config[:cookbook_path].size == 1 && Chef::Config[:cookbook_path].first !~ /cookbook/
|
502
|
+
Chef::Config[:chefspec_cookbook_root] = @options[:cookbook_root]
|
503
|
+
end
|
504
|
+
Chef::Config[:no_lazy_load] = true
|
505
|
+
Chef::Config[:role_path] = Array(@options[:role_path])
|
506
|
+
Chef::Config[:force_logger] = true
|
507
|
+
Chef::Config[:solo] = true
|
508
|
+
Chef::Config[:solo_legacy_mode] = true
|
509
|
+
Chef::Config[:use_policyfile] = false
|
510
|
+
Chef::Config[:environment_path] = @options[:environment_path]
|
511
|
+
end
|
512
|
+
|
409
513
|
end
|
410
514
|
end
|