chefspec 5.0.0 → 7.0.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 +17 -25
- data/CHANGELOG.md +506 -371
- data/Gemfile +9 -0
- data/README.md +118 -75
- data/chefspec.gemspec +4 -5
- data/examples/apt_package/recipes/purge.rb +2 -2
- data/examples/apt_package/recipes/reconfig.rb +2 -2
- data/examples/apt_package/recipes/remove.rb +2 -2
- data/examples/apt_package/recipes/upgrade.rb +2 -2
- data/examples/apt_package/spec/install_spec.rb +4 -1
- data/examples/apt_package/spec/purge_spec.rb +4 -1
- data/examples/apt_package/spec/reconfig_spec.rb +4 -1
- data/examples/apt_package/spec/remove_spec.rb +4 -1
- data/examples/apt_package/spec/upgrade_spec.rb +4 -1
- data/examples/apt_repository/spec/add_spec.rb +4 -1
- data/examples/apt_repository/spec/remove_spec.rb +4 -1
- data/examples/apt_update/recipes/periodic.rb +1 -1
- data/examples/apt_update/spec/periodic_spec.rb +5 -2
- data/examples/apt_update/spec/update_spec.rb +4 -1
- data/examples/attributes/spec/default_spec.rb +1 -1
- data/examples/batch/recipes/run.rb +0 -4
- data/examples/batch/spec/run_spec.rb +4 -10
- data/examples/bff_package/recipes/install.rb +13 -0
- data/examples/bff_package/recipes/purge.rb +13 -0
- data/examples/bff_package/recipes/remove.rb +13 -0
- data/examples/bff_package/recipes/upgrade.rb +13 -0
- data/examples/bff_package/spec/install_spec.rb +23 -0
- data/examples/bff_package/spec/purge_spec.rb +19 -0
- data/examples/bff_package/spec/remove_spec.rb +19 -0
- data/examples/bff_package/spec/upgrade_spec.rb +19 -0
- data/examples/cab_package/recipes/install.rb +13 -0
- data/examples/cab_package/recipes/remove.rb +13 -0
- data/examples/cab_package/spec/install_spec.rb +26 -0
- data/examples/cab_package/spec/remove_spec.rb +22 -0
- 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 +4 -6
- data/examples/chocolatey_package/spec/remove_spec.rb +4 -6
- data/examples/chocolatey_package/spec/upgrade_spec.rb +4 -6
- data/examples/compile_time/spec/default_spec.rb +1 -1
- data/examples/cookbook_file/spec/create_if_missing_spec.rb +3 -3
- data/examples/cookbook_file/spec/create_spec.rb +3 -3
- 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/providers/thing.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/libraries/matchers.rb +5 -0
- data/examples/custom_resource/recipes/default.rb +1 -0
- data/examples/custom_resource/resources/custom_resource.rb +9 -0
- data/examples/custom_resource/spec/default_spec.rb +18 -0
- 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 +4 -4
- data/examples/directory/spec/delete_spec.rb +3 -3
- data/examples/dnf_package/recipes/install.rb +13 -0
- data/examples/dnf_package/recipes/purge.rb +13 -0
- data/examples/dnf_package/recipes/remove.rb +13 -0
- data/examples/dnf_package/recipes/upgrade.rb +13 -0
- data/examples/dnf_package/spec/install_spec.rb +26 -0
- data/examples/dnf_package/spec/purge_spec.rb +22 -0
- data/examples/dnf_package/spec/remove_spec.rb +22 -0
- data/examples/dnf_package/spec/upgrade_spec.rb +22 -0
- data/examples/do_nothing/spec/default_spec.rb +1 -1
- data/examples/dpkg_package/spec/install_spec.rb +4 -6
- data/examples/dpkg_package/spec/purge_spec.rb +4 -6
- data/examples/dpkg_package/spec/remove_spec.rb +4 -6
- data/examples/dsc_resource/recipes/{default.rb → run.rb} +6 -6
- data/examples/dsc_resource/spec/{default_spec.rb → run_spec.rb} +8 -10
- data/examples/dsc_script/recipes/run.rb +12 -0
- data/examples/dsc_script/spec/run_spec.rb +16 -0
- data/examples/env/spec/create_spec.rb +4 -6
- data/examples/env/spec/delete_spec.rb +4 -6
- data/examples/env/spec/modify_spec.rb +4 -6
- 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 +3 -3
- data/examples/file/spec/create_spec.rb +3 -3
- 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 +4 -1
- data/examples/freebsd_package/spec/remove_spec.rb +4 -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/libraries/resource_service.rb +1 -1
- data/examples/heavy_provider_light_resource/recipes/default.rb +1 -2
- data/examples/heavy_provider_light_resource/spec/provider_service_spec.rb +2 -2
- data/examples/homebrew_package/recipes/install.rb +13 -0
- data/examples/homebrew_package/recipes/purge.rb +13 -0
- data/examples/homebrew_package/recipes/remove.rb +13 -0
- data/examples/homebrew_package/recipes/upgrade.rb +13 -0
- data/examples/homebrew_package/spec/install_spec.rb +23 -0
- data/examples/homebrew_package/spec/purge_spec.rb +19 -0
- data/examples/homebrew_package/spec/remove_spec.rb +19 -0
- data/examples/homebrew_package/spec/upgrade_spec.rb +19 -0
- 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 +4 -6
- data/examples/ips_package/spec/remove_spec.rb +4 -6
- data/examples/ips_package/spec/upgrade_spec.rb +4 -6
- data/examples/launchd/recipes/create.rb +5 -0
- data/examples/launchd/recipes/create_if_missing.rb +3 -0
- data/examples/launchd/recipes/delete.rb +3 -0
- data/examples/launchd/recipes/disable.rb +3 -0
- data/examples/launchd/recipes/enable.rb +3 -0
- data/examples/launchd/spec/create_if_missing_spec.rb +10 -0
- data/examples/launchd/spec/create_spec.rb +14 -0
- data/examples/launchd/spec/delete_spec.rb +10 -0
- data/examples/launchd/spec/disable_spec.rb +10 -0
- data/examples/launchd/spec/enable_spec.rb +10 -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/recipes/install.rb +13 -0
- data/examples/msu_package/recipes/remove.rb +13 -0
- data/examples/msu_package/spec/install_spec.rb +26 -0
- data/examples/msu_package/spec/remove_spec.rb +22 -0
- data/examples/multiple_actions/recipes/reversed.rb +9 -0
- data/examples/multiple_actions/recipes/sequential.rb +5 -3
- data/examples/multiple_actions/spec/default_spec.rb +1 -1
- data/examples/multiple_actions/spec/reversed_spec.rb +17 -0
- data/examples/multiple_actions/spec/sequential_spec.rb +5 -4
- data/examples/multiple_run_action/recipes/default.rb +2 -2
- data/examples/multiple_run_action/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/openbsd_package/recipes/install.rb +13 -0
- data/examples/openbsd_package/recipes/purge.rb +13 -0
- data/examples/openbsd_package/recipes/remove.rb +13 -0
- data/examples/openbsd_package/recipes/upgrade.rb +13 -0
- data/examples/openbsd_package/spec/install_spec.rb +23 -0
- data/examples/openbsd_package/spec/purge_spec.rb +19 -0
- data/examples/openbsd_package/spec/remove_spec.rb +19 -0
- data/examples/openbsd_package/spec/upgrade_spec.rb +19 -0
- data/examples/osx_profile/recipes/install.rb +8 -0
- data/examples/osx_profile/recipes/remove.rb +8 -0
- data/examples/osx_profile/spec/install_spec.rb +15 -0
- data/examples/osx_profile/spec/remove_spec.rb +13 -0
- data/examples/package/recipes/install.rb +1 -1
- data/examples/package/recipes/purge.rb +1 -1
- data/examples/package/recipes/reconfig.rb +1 -1
- data/examples/package/recipes/remove.rb +1 -1
- data/examples/package/recipes/upgrade.rb +1 -1
- data/examples/package/spec/install_spec.rb +2 -2
- data/examples/package/spec/purge_spec.rb +2 -2
- data/examples/package/spec/reconfig_spec.rb +2 -2
- data/examples/package/spec/remove_spec.rb +2 -2
- data/examples/package/spec/upgrade_spec.rb +2 -2
- data/examples/pacman_package/spec/install_spec.rb +4 -6
- data/examples/pacman_package/spec/purge_spec.rb +4 -6
- data/examples/pacman_package/spec/remove_spec.rb +4 -6
- data/examples/pacman_package/spec/upgrade_spec.rb +4 -6
- data/examples/paludis_package/recipes/install.rb +13 -0
- data/examples/paludis_package/recipes/purge.rb +13 -0
- data/examples/paludis_package/recipes/remove.rb +13 -0
- data/examples/paludis_package/recipes/upgrade.rb +13 -0
- data/examples/paludis_package/spec/install_spec.rb +23 -0
- data/examples/paludis_package/spec/purge_spec.rb +19 -0
- data/examples/paludis_package/spec/remove_spec.rb +19 -0
- data/examples/paludis_package/spec/upgrade_spec.rb +19 -0
- data/examples/portage_package/spec/install_spec.rb +4 -1
- data/examples/portage_package/spec/purge_spec.rb +4 -1
- data/examples/portage_package/spec/remove_spec.rb +4 -1
- data/examples/portage_package/spec/upgrade_spec.rb +4 -1
- data/examples/powershell_script/recipes/run.rb +0 -4
- data/examples/powershell_script/spec/run_spec.rb +4 -10
- data/examples/reboot/spec/cancel_spec.rb +1 -2
- data/examples/reboot/spec/now_spec.rb +1 -2
- data/examples/reboot/spec/request_spec.rb +1 -2
- data/examples/registry_key/spec/create_if_missing_spec.rb +4 -1
- data/examples/registry_key/spec/create_spec.rb +4 -1
- data/examples/registry_key/spec/delete_key_spec.rb +4 -1
- data/examples/registry_key/spec/delete_spec.rb +4 -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/roles/role.rb +4 -4
- 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 +4 -6
- data/examples/rpm_package/spec/remove_spec.rb +4 -6
- data/examples/rpm_package/spec/upgrade_spec.rb +4 -6
- data/examples/ruby_block/recipes/create.rb +8 -0
- data/examples/ruby_block/spec/create_spec.rb +13 -0
- data/examples/ruby_block/spec/run_spec.rb +1 -1
- data/examples/script/recipes/run_bash.rb +0 -4
- data/examples/script/recipes/run_csh.rb +0 -4
- data/examples/script/recipes/run_ksh.rb +9 -0
- data/examples/script/recipes/run_perl.rb +0 -4
- data/examples/script/recipes/run_python.rb +0 -4
- data/examples/script/recipes/run_ruby.rb +0 -4
- data/examples/script/recipes/run_script.rb +0 -4
- data/examples/script/spec/run_bash_spec.rb +1 -5
- data/examples/script/spec/run_csh_spec.rb +1 -5
- data/examples/script/spec/run_ksh_spec.rb +19 -0
- data/examples/script/spec/run_perl_spec.rb +1 -5
- data/examples/script/spec/run_python_spec.rb +1 -5
- data/examples/script/spec/run_ruby_spec.rb +1 -5
- data/examples/script/spec/run_script_spec.rb +1 -5
- data/examples/server/spec/client_spec.rb +2 -2
- data/examples/server/spec/data_bag_spec.rb +9 -11
- data/examples/server/spec/environment_spec.rb +1 -1
- data/examples/server/spec/exotic_port_spec.rb +17 -0
- data/examples/server/spec/node_spec.rb +6 -6
- 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 +2 -2
- data/examples/service/recipes/disable.rb +1 -1
- data/examples/service/recipes/enable.rb +1 -1
- data/examples/service/recipes/reload.rb +1 -1
- data/examples/service/recipes/restart.rb +1 -1
- data/examples/service/recipes/start.rb +1 -1
- data/examples/service/recipes/stop.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 +4 -1
- data/examples/smartos_package/spec/remove_spec.rb +4 -1
- data/examples/smartos_package/spec/upgrade_spec.rb +4 -1
- data/examples/solaris_package/recipes/upgrade.rb +13 -0
- data/examples/solaris_package/spec/install_spec.rb +4 -1
- data/examples/solaris_package/spec/remove_spec.rb +4 -1
- data/examples/solaris_package/spec/upgrade_spec.rb +22 -0
- data/examples/state_attrs/providers/lwrp.rb +0 -1
- data/examples/state_attrs/spec/default_spec.rb +1 -1
- data/examples/step_into/spec/default_spec.rb +4 -4
- data/examples/stub_command/spec/default_spec.rb +3 -3
- data/examples/stub_data_bag/spec/default_spec.rb +3 -3
- data/examples/stub_data_bag_item/spec/default_spec.rb +5 -5
- data/examples/stub_search/recipes/block.rb +3 -0
- data/examples/stub_search/recipes/default.rb +2 -5
- data/examples/stub_search/spec/block_spec.rb +27 -0
- data/examples/stub_search/spec/default_spec.rb +5 -5
- 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 -2
- 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/recipes/create.rb +3 -0
- data/examples/systemd_unit/recipes/delete.rb +3 -0
- data/examples/systemd_unit/recipes/disable.rb +3 -0
- data/examples/systemd_unit/recipes/enable.rb +3 -0
- data/examples/systemd_unit/recipes/mask.rb +3 -0
- data/examples/systemd_unit/recipes/reload_or_restart.rb +3 -0
- data/examples/systemd_unit/recipes/reload_or_try_restart.rb +3 -0
- data/examples/systemd_unit/recipes/restart.rb +3 -0
- data/examples/systemd_unit/recipes/start.rb +3 -0
- data/examples/systemd_unit/recipes/stop.rb +3 -0
- data/examples/systemd_unit/recipes/try_restart.rb +3 -0
- data/examples/systemd_unit/recipes/unmask.rb +3 -0
- data/examples/systemd_unit/spec/create_spec.rb +10 -0
- data/examples/systemd_unit/spec/delete_spec.rb +10 -0
- data/examples/systemd_unit/spec/disable_spec.rb +10 -0
- data/examples/systemd_unit/spec/enable_spec.rb +10 -0
- data/examples/systemd_unit/spec/mask_spec.rb +10 -0
- data/examples/systemd_unit/spec/reload_or_restart_spec.rb +10 -0
- data/examples/systemd_unit/spec/reload_or_try_restart_spec.rb +10 -0
- data/examples/systemd_unit/spec/restart_spec.rb +10 -0
- data/examples/systemd_unit/spec/start_spec.rb +10 -0
- data/examples/systemd_unit/spec/stop_spec.rb +10 -0
- data/examples/systemd_unit/spec/try_restart_spec.rb +10 -0
- data/examples/systemd_unit/spec/unmask_spec.rb +10 -0
- data/examples/template/spec/create_if_missing_spec.rb +3 -3
- data/examples/template/spec/create_spec.rb +3 -3
- 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 +3 -3
- data/examples/user/spec/create_spec.rb +4 -1
- data/examples/user/spec/lock_spec.rb +4 -1
- data/examples/user/spec/manage_spec.rb +4 -1
- data/examples/user/spec/modify_spec.rb +4 -1
- data/examples/user/spec/remove_spec.rb +4 -1
- data/examples/user/spec/unlock_spec.rb +4 -1
- data/examples/windows_package/spec/install_spec.rb +4 -6
- data/examples/windows_package/spec/remove_spec.rb +4 -6
- data/examples/windows_service/spec/configure_startup_spec.rb +4 -6
- data/examples/windows_service/spec/disable_spec.rb +4 -6
- data/examples/windows_service/spec/enable_spec.rb +4 -6
- data/examples/windows_service/spec/reload_spec.rb +4 -6
- data/examples/windows_service/spec/restart_spec.rb +4 -6
- data/examples/windows_service/spec/start_spec.rb +4 -6
- data/examples/windows_service/spec/stop_spec.rb +4 -6
- data/examples/yum_package/spec/install_spec.rb +4 -1
- data/examples/yum_package/spec/purge_spec.rb +4 -1
- data/examples/yum_package/spec/remove_spec.rb +4 -1
- data/examples/yum_package/spec/upgrade_spec.rb +4 -1
- data/examples/yum_repository/recipes/add.rb +8 -0
- data/examples/yum_repository/recipes/create.rb +8 -0
- data/examples/yum_repository/recipes/delete.rb +3 -0
- data/examples/yum_repository/recipes/makecache.rb +3 -0
- data/examples/yum_repository/recipes/remove.rb +7 -0
- data/examples/yum_repository/spec/add_spec.rb +12 -0
- data/examples/yum_repository/spec/create_spec.rb +17 -0
- data/examples/yum_repository/spec/delete_spec.rb +12 -0
- data/examples/yum_repository/spec/makecache_spec.rb +12 -0
- data/examples/yum_repository/spec/remove_spec.rb +12 -0
- data/examples/zypper_package/recipes/install.rb +13 -0
- data/examples/zypper_package/recipes/purge.rb +13 -0
- data/examples/zypper_package/recipes/remove.rb +13 -0
- data/examples/zypper_package/recipes/upgrade.rb +13 -0
- data/examples/zypper_package/spec/install_spec.rb +23 -0
- data/examples/zypper_package/spec/purge_spec.rb +19 -0
- data/examples/zypper_package/spec/remove_spec.rb +19 -0
- data/examples/zypper_package/spec/upgrade_spec.rb +19 -0
- data/features/apt_repository.feature +15 -0
- data/features/apt_update.feature +13 -0
- data/features/attributes.feature +1 -1
- data/features/bff_package.feature +12 -0
- data/features/cab_package.feature +21 -0
- data/features/chocolatey_package.feature +1 -6
- data/features/compile_time.feature +1 -1
- data/features/custom_resource.feature +7 -0
- data/features/dnf_package.feature +26 -0
- data/features/dsc_resource.feature +5 -4
- data/features/dsc_script.feature +10 -0
- data/features/exotic_zero_port.feature +7 -0
- data/features/homebrew_package.feature +12 -0
- data/features/launchd.feature +17 -0
- data/features/msu_package.feature +23 -0
- data/features/multiple_actions.feature +1 -0
- data/features/notifications.feature +0 -7
- data/features/openbsd_package.feature +12 -0
- data/features/osx_profile.feature +13 -0
- data/features/paludis_package.feature +12 -0
- data/features/roles.feature +1 -1
- data/features/ruby_block.feature +1 -0
- data/features/script.feature +1 -0
- data/features/server_on_disk.feature +16 -0
- data/features/solaris_package.feature +1 -0
- data/features/stub_search.feature +1 -1
- data/features/subscribes.feature +0 -7
- data/features/support/env.rb +8 -0
- data/features/support/exotic_zero_port.rb +3 -0
- data/features/support/on_disk.rb +7 -0
- data/features/systemd_unit.feature +27 -0
- data/features/windows_package.feature +0 -4
- data/features/yum_repository.feature +23 -0
- data/features/{easy_install_package.feature → zypper_package.feature} +2 -2
- data/lib/chefspec/api/bff_package.rb +154 -0
- data/lib/chefspec/api/cab_package.rb +80 -0
- data/lib/chefspec/api/dnf_package.rb +154 -0
- data/lib/chefspec/api/dsc_script.rb +37 -0
- data/lib/chefspec/api/homebrew_package.rb +154 -0
- data/lib/chefspec/api/launchd.rb +151 -0
- data/lib/chefspec/api/msu_package.rb +81 -0
- data/lib/chefspec/api/openbsd_package.rb +155 -0
- data/lib/chefspec/api/osx_profile.rb +63 -0
- data/lib/chefspec/api/paludis_package.rb +155 -0
- data/lib/chefspec/api/ruby_block.rb +31 -0
- data/lib/chefspec/api/script.rb +39 -0
- data/lib/chefspec/api/solaris_package.rb +37 -0
- data/lib/chefspec/api/systemd_unit.rb +353 -0
- data/lib/chefspec/api/yum_repository.rb +130 -0
- data/lib/chefspec/api/zypper_package.rb +154 -0
- data/lib/chefspec/api.rb +15 -0
- data/lib/chefspec/coverage.rb +25 -7
- data/lib/chefspec/extensions/chef/data_query.rb +6 -1
- data/lib/chefspec/extensions/chef/lwrp_base.rb +21 -35
- data/lib/chefspec/macros.rb +1 -1
- data/lib/chefspec/matchers/resource_matcher.rb +20 -27
- data/lib/chefspec/rspec.rb +3 -0
- data/lib/chefspec/server_methods.rb +9 -12
- data/lib/chefspec/server_runner.rb +2 -42
- data/lib/chefspec/solo_runner.rb +11 -10
- data/lib/chefspec/version.rb +1 -1
- data/lib/chefspec/zero_server.rb +140 -0
- data/lib/chefspec.rb +0 -1
- data/spec/unit/macros_spec.rb +2 -2
- data/spec/unit/solo_runner_spec.rb +3 -2
- data/templates/errors/may_need_to_specify_platform.erb +1 -1
- metadata +195 -26
- data/examples/easy_install_package/recipes/install.rb +0 -13
- data/examples/easy_install_package/recipes/purge.rb +0 -13
- data/examples/easy_install_package/recipes/remove.rb +0 -13
- data/examples/easy_install_package/recipes/upgrade.rb +0 -13
- data/examples/easy_install_package/spec/install_spec.rb +0 -23
- data/examples/easy_install_package/spec/purge_spec.rb +0 -19
- data/examples/easy_install_package/spec/remove_spec.rb +0 -19
- data/examples/easy_install_package/spec/upgrade_spec.rb +0 -19
- data/gemfiles/chefspec.gemfile +0 -15
- data/lib/chefspec/chef_backwards_compat.rb +0 -79
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
ChefSpec
|
|
2
|
-
========
|
|
3
|
-
[][gem]
|
|
4
|
-
[][travis]
|
|
1
|
+
# ChefSpec
|
|
5
2
|
|
|
6
|
-
[
|
|
7
|
-
[travis]: http://travis-ci.org/sethvargo/chefspec
|
|
3
|
+
[](https://badge.fury.io/rb/chefspec) [](https://travis-ci.org/sethvargo/chefspec)
|
|
8
4
|
|
|
9
5
|
ChefSpec is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.
|
|
10
6
|
|
|
@@ -13,33 +9,29 @@ ChefSpec runs your cookbook(s) locally with Chef Solo without actually convergin
|
|
|
13
9
|
- It's really fast!
|
|
14
10
|
- Your tests can vary node attributes, operating systems, and search results to assert behavior under varying conditions.
|
|
15
11
|
|
|
12
|
+
## What people are saying
|
|
16
13
|
|
|
17
|
-
What people are saying
|
|
18
|
-
----------------------
|
|
19
14
|
> I just wanted to drop you a line to say "HELL YES!" to ChefSpec. - [Joe Goggins](https://twitter.com/jgoggins)
|
|
20
15
|
|
|
21
16
|
> OK ChefSpec is my new best friend. Delightful few hours working with it. - [Michael Ivey](https://twitter.com/ivey)
|
|
22
17
|
|
|
23
18
|
**Chat with us - [#chefspec](irc://irc.freenode.net/chefspec) on Freenode**
|
|
24
19
|
|
|
20
|
+
## Important Notes
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
---------------
|
|
28
|
-
- **ChefSpec requires Ruby 2.1 or later and Chef 12.0.2 or later!**
|
|
22
|
+
- **ChefSpec requires Ruby 2.2 or later and Chef 12.14.89 or later!**
|
|
29
23
|
- **This documentation corresponds to the master branch, which may be unreleased. Please check the README of the latest git tag or the gem's source for your version's documentation!**
|
|
30
24
|
- **Each resource matcher is self-documented using [Yard](http://rubydoc.info/github/sethvargo/chefspec) and has a corresponding aruba test from the [examples directory](https://github.com/sethvargo/chefspec/tree/master/examples).**
|
|
31
25
|
- **ChefSpec aims to maintain compatibility with the two most recent minor versions of Chef.** If you are running an older version of Chef it may work, or you will need to run an older version of ChefSpec.
|
|
32
26
|
|
|
27
|
+
## Notes on Compatibility with Chef Versions
|
|
33
28
|
|
|
34
|
-
Notes on Compatibility with Chef Versions
|
|
35
|
-
-----------------------------------------
|
|
36
29
|
As a general rule, if it is tested in the Travis CI matrix, it is a supported version. The section below details any specific versions that are _not_ supported and why:
|
|
37
30
|
|
|
38
31
|
Additionally, if you look at a cucumber feature and see a tag like `@not_chef_x_y_z`, that means that particular functionality is not supported on those versions of Chef.
|
|
39
32
|
|
|
33
|
+
## Writing a Cookbook Example
|
|
40
34
|
|
|
41
|
-
Writing a Cookbook Example
|
|
42
|
-
--------------------------
|
|
43
35
|
If you want `knife` to automatically generate spec stubs for you, install [knife-spec](https://github.com/sethvargo/knife-spec).
|
|
44
36
|
|
|
45
37
|
Given an extremely basic Chef recipe that just installs an operating system package:
|
|
@@ -54,7 +46,7 @@ the associated ChefSpec test might look like:
|
|
|
54
46
|
require 'chefspec'
|
|
55
47
|
|
|
56
48
|
describe 'example::default' do
|
|
57
|
-
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
|
49
|
+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }
|
|
58
50
|
|
|
59
51
|
it 'installs foo' do
|
|
60
52
|
expect(chef_run).to install_package('foo')
|
|
@@ -65,14 +57,13 @@ end
|
|
|
65
57
|
Let's step through this file to see what is happening:
|
|
66
58
|
|
|
67
59
|
1. At the top of the spec file we require the chefspec gem. This is required so that our custom matchers are loaded. In larger projects, it is common practice to create a file named "spec_helper.rb" and include ChefSpec and perform other setup tasks in that file.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
2. The `describe` keyword is part of RSpec and indicates that everything nested beneath is describing the `example::default` recipe. The convention is to have a separate spec for each recipe in your cookbook.
|
|
61
|
+
3. The `let` block on creates the `ChefSpec:SoloRunner` with mocked Ohai data for Ubuntu 16.04 from [Fauxhai](https://github.com/customink/fauxhai). It then does a fake Chef run with the run_list of `example::default`. Any subsequent examples can then refer to `chef_run` in order to make assertions about the resources that were created during the mock converge.
|
|
62
|
+
4. The `described_recipe` macro is a ChefSpec helper method that infers the recipe from the `describe` block. Alternatively you could specify the recipe directly.
|
|
63
|
+
5. The `it` block is an example specifying that the `foo` package is installed. Normally you will have multiple `it` blocks per recipe, each making a single assertion.
|
|
72
64
|
|
|
65
|
+
## Configuration
|
|
73
66
|
|
|
74
|
-
Configuration
|
|
75
|
-
-------------
|
|
76
67
|
ChefSpec exposes a configuration layer at the global level and at the `Runner` level. The following settings are available:
|
|
77
68
|
|
|
78
69
|
```ruby
|
|
@@ -88,7 +79,7 @@ RSpec.configure do |config|
|
|
|
88
79
|
config.environment_path = '/var/environments'
|
|
89
80
|
|
|
90
81
|
# Specify the path for Chef Solo file cache path (default: nil)
|
|
91
|
-
config.file_cache_path =
|
|
82
|
+
config.file_cache_path = Chef::Config[:file_cache_path]
|
|
92
83
|
|
|
93
84
|
# Specify the Chef log_level (default: :warn)
|
|
94
85
|
config.log_level = :debug
|
|
@@ -111,7 +102,7 @@ Values specified at the initialization of a "Runner" merge and take precedence o
|
|
|
111
102
|
ChefSpec::SoloRunner.new(version: '16.04')
|
|
112
103
|
|
|
113
104
|
# Use a different operating system platform and version
|
|
114
|
-
ChefSpec::SoloRunner.new(platform: 'centos', version: '7.
|
|
105
|
+
ChefSpec::SoloRunner.new(platform: 'centos', version: '7.3.1611')
|
|
115
106
|
|
|
116
107
|
# Specify a different cookbook_path
|
|
117
108
|
ChefSpec::SoloRunner.new(cookbook_path: '/var/my/other/path', role_path: '/var/my/roles')
|
|
@@ -120,15 +111,33 @@ ChefSpec::SoloRunner.new(cookbook_path: '/var/my/other/path', role_path: '/var/m
|
|
|
120
111
|
# This can be overridden by passing the `file_cache_path` option.
|
|
121
112
|
# Note: Resources containing `Chef::Config[:file_cache_path]` in their name or
|
|
122
113
|
# attributes, will fail unless this option is specified.
|
|
123
|
-
ChefSpec::SoloRunner.new(file_cache_path:
|
|
114
|
+
ChefSpec::SoloRunner.new(file_cache_path: Chef::Config[:file_cache_path])
|
|
124
115
|
|
|
125
116
|
# Add debug log output
|
|
126
117
|
ChefSpec::SoloRunner.new(log_level: :debug).converge(described_recipe)
|
|
127
118
|
```
|
|
128
119
|
|
|
129
|
-
**NOTE** You do not _need_ to specify a platform and version to use ChefSpec. However, some cookbooks may rely on [Ohai](http://github.com/chef/ohai) data that ChefSpec cannot not automatically generate. Specifying the `platform` and `version` keys instructs ChefSpec to load stubbed Ohai attributes from another platform using [fauxhai](https://github.com/customink/fauxhai).
|
|
120
|
+
**NOTE** You do not _need_ to specify a platform and version to use ChefSpec. However, some cookbooks may rely on [Ohai](http://github.com/chef/ohai) data that ChefSpec cannot not automatically generate. Specifying the `platform` and `version` keys instructs ChefSpec to load stubbed Ohai attributes from another platform using [fauxhai](https://github.com/customink/fauxhai). See the [PLATFORMS.md file](https://github.com/customink/fauxhai/blob/master/PLATFORMS.md) in the Fauxhai repo for a complete list of platforms and versions for use with ChefSpec.
|
|
121
|
+
|
|
122
|
+
### ChefZero Server
|
|
123
|
+
|
|
124
|
+
The `ServerRunner` uses a [chef-zero](https://github.com/chef/chef-zero) instance as a stand-in for a full Chef Server. The instance is created at the initiation of the ChefSpec suite and is terminated at its completion. In between each test the state of the ChefZero server is completely reset.
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
RSpec.configure do |config|
|
|
128
|
+
# When using ChefSpec::ServerRunner, specify the data storage method (options: in_memory, on_disk; default: in_memory)
|
|
129
|
+
# If you are in a low-memory environment, setting this value to :on_disk may improve speed and/or reliability.
|
|
130
|
+
config.server_runner_data_store = :on_disk
|
|
131
|
+
|
|
132
|
+
# Whether or not to clear the cookbooks on the ChefZero instance in-between each test (default: true)
|
|
133
|
+
# For most people, not clearing the cookbooks will drastically improve test execution time. This is a
|
|
134
|
+
# good option for people who are using chefspec within the context of a single Berksfile or Policyfile.
|
|
135
|
+
config.server_runner_clear_cookbooks = false
|
|
136
|
+
end
|
|
137
|
+
```
|
|
130
138
|
|
|
131
139
|
### Berkshelf
|
|
140
|
+
|
|
132
141
|
If you are using Berkshelf, simply require `chefspec/berkshelf` in your `spec_helper` after requiring `chefspec`:
|
|
133
142
|
|
|
134
143
|
```ruby
|
|
@@ -169,8 +178,7 @@ Requiring this file will:
|
|
|
169
178
|
- Download all the dependencies listed in your `Cheffile` into the temporary directory
|
|
170
179
|
- Set ChefSpec's `cookbook_path` to the temporary directory
|
|
171
180
|
|
|
172
|
-
**NOTE** In order to test the cookbook in the current working directory, you
|
|
173
|
-
have to write your `Cheffile` like this:
|
|
181
|
+
**NOTE** In order to test the cookbook in the current working directory, you have to write your `Cheffile` like this:
|
|
174
182
|
|
|
175
183
|
```ruby
|
|
176
184
|
# Cheffile
|
|
@@ -180,6 +188,7 @@ cookbook 'name_of_your_cookbook', path: '.'
|
|
|
180
188
|
```
|
|
181
189
|
|
|
182
190
|
### Policyfile
|
|
191
|
+
|
|
183
192
|
If you are using Chef Policies with ChefDK, simply require `chefspec/policyfile` in your `spec_helper`, and ensure you are using the `ChefSpec::ServerRunner` - Chef Solo does not support the exported repository format because the cookbook names use the unique version identifier.
|
|
184
193
|
|
|
185
194
|
```ruby
|
|
@@ -203,8 +212,8 @@ default_source :community
|
|
|
203
212
|
cookbook 'my-cookbook', path: '.'
|
|
204
213
|
```
|
|
205
214
|
|
|
206
|
-
Running Specs
|
|
207
|
-
|
|
215
|
+
## Running Specs
|
|
216
|
+
|
|
208
217
|
ChefSpec is actually an RSpec extension, so you can run your tests using the RSpec CLI:
|
|
209
218
|
|
|
210
219
|
```bash
|
|
@@ -219,9 +228,8 @@ $ rspec spec/unit/recipes/default_spec.rb --color
|
|
|
219
228
|
|
|
220
229
|
For more information on the RSpec CLI, please see the [documentation](https://relishapp.com/rspec/rspec-core/docs/command-line).
|
|
221
230
|
|
|
231
|
+
## Making Assertions
|
|
222
232
|
|
|
223
|
-
Making Assertions
|
|
224
|
-
-----------------
|
|
225
233
|
ChefSpec asserts that resource actions have been performed. In general, ChefSpec follows the following pattern:
|
|
226
234
|
|
|
227
235
|
```ruby
|
|
@@ -280,7 +288,8 @@ ChefSpec includes matchers for all of Chef's core resources using the above sche
|
|
|
280
288
|
|
|
281
289
|
Additionally, ChefSpec includes the following helpful matchers. They are also [documented in Yard](http://rubydoc.info/github/sethvargo/chefspec), but they are included here because they do not follow the "general pattern".
|
|
282
290
|
|
|
283
|
-
|
|
291
|
+
### include_recipe
|
|
292
|
+
|
|
284
293
|
Assert that the Chef run included a recipe from another cookbook
|
|
285
294
|
|
|
286
295
|
```ruby
|
|
@@ -305,7 +314,8 @@ describe 'example::default' do
|
|
|
305
314
|
end
|
|
306
315
|
```
|
|
307
316
|
|
|
308
|
-
|
|
317
|
+
### notify
|
|
318
|
+
|
|
309
319
|
Assert that a resource notifies another in the Chef run
|
|
310
320
|
|
|
311
321
|
```ruby
|
|
@@ -313,7 +323,8 @@ resource = chef_run.template('/etc/foo')
|
|
|
313
323
|
expect(resource).to notify('service[apache2]').to(:restart).immediately
|
|
314
324
|
```
|
|
315
325
|
|
|
316
|
-
|
|
326
|
+
### subscribes
|
|
327
|
+
|
|
317
328
|
Assert that a resource subscribes to another in the Chef run
|
|
318
329
|
|
|
319
330
|
```ruby
|
|
@@ -321,7 +332,8 @@ resource = chef_run.service('apache2')
|
|
|
321
332
|
expect(resource).to subscribe_to('template[/etc/foo]').on(:create).delayed
|
|
322
333
|
```
|
|
323
334
|
|
|
324
|
-
|
|
335
|
+
### render_file
|
|
336
|
+
|
|
325
337
|
Assert that the Chef run renders a file (with optional content); this will match `cookbook_file`, `file`, and `template` resources and can also check the resulting content
|
|
326
338
|
|
|
327
339
|
```ruby
|
|
@@ -360,7 +372,8 @@ expect(chef_run).to install_package('apache2').at_converge_time
|
|
|
360
372
|
|
|
361
373
|
Since "converge time" is the default behavior for all recipes, this test might be redundant and the predicate could be dropped depending on your situation.
|
|
362
374
|
|
|
363
|
-
|
|
375
|
+
### do_nothing
|
|
376
|
+
|
|
364
377
|
Assert that a resource performs no action
|
|
365
378
|
|
|
366
379
|
```ruby
|
|
@@ -370,9 +383,8 @@ expect(resource).to do_nothing
|
|
|
370
383
|
|
|
371
384
|
**For more complex examples, please see the [examples directory](https://github.com/sethvargo/chefspec/tree/master/examples) or the [Yard documentation](http://rubydoc.info/github/sethvargo/chefspec).**
|
|
372
385
|
|
|
386
|
+
## Setting node Attributes
|
|
373
387
|
|
|
374
|
-
Setting node Attributes
|
|
375
|
-
-----------------------
|
|
376
388
|
Node attribute can be set when creating the `Runner`. The initializer yields a block that gives full access to the node object:
|
|
377
389
|
|
|
378
390
|
```ruby
|
|
@@ -386,6 +398,7 @@ end
|
|
|
386
398
|
```
|
|
387
399
|
|
|
388
400
|
### Automatic attributes
|
|
401
|
+
|
|
389
402
|
ChefSpec provides mocked automatic Ohai data using [fauxhai](https://github.com/customink/fauxhai). To mock out `automatic` attributes, you must use the `automatic` key:
|
|
390
403
|
|
|
391
404
|
```ruby
|
|
@@ -415,8 +428,8 @@ describe 'example::default' do
|
|
|
415
428
|
end
|
|
416
429
|
```
|
|
417
430
|
|
|
418
|
-
Using a Chef Server
|
|
419
|
-
|
|
431
|
+
## Using a Chef Server
|
|
432
|
+
|
|
420
433
|
All the examples thus far have used the `ChefSpec::SoloRunner`, which runs ChefSpec in Chef Solo mode. ChefSpec also includes the ability to create in-memory Chef Servers. This server can be populated with fake data and used to test search, data bags, and other "server-only" features.
|
|
421
434
|
|
|
422
435
|
To use the ChefSpec server, simply replace `ChefSpec::SoloRunner` with `ChefSpec::ServerRunner`:
|
|
@@ -431,6 +444,7 @@ end
|
|
|
431
444
|
This will automatically create a Chef Server, synchronize all the cookbooks in your `cookbook_path`, and wire all the internals of Chef together. Recipe calls to `search`, `data_bag` and `data_bag_item` will now query this ChefSpec server.
|
|
432
445
|
|
|
433
446
|
### DSL
|
|
447
|
+
|
|
434
448
|
The ChefSpec server includes a collection of helpful DSL methods for populating data into the Chef Server.
|
|
435
449
|
|
|
436
450
|
Create a client:
|
|
@@ -489,7 +503,7 @@ end
|
|
|
489
503
|
You may also use the `stub_node` macro, which will create a new `Chef::Node` object and accepts the same parameters as the Chef Runner and a Fauxhai object:
|
|
490
504
|
|
|
491
505
|
```ruby
|
|
492
|
-
www = stub_node(platform: 'ubuntu', version: '
|
|
506
|
+
www = stub_node(platform: 'ubuntu', version: '16.04') do |node|
|
|
493
507
|
node.normal['attribute'] = 'value'
|
|
494
508
|
end
|
|
495
509
|
|
|
@@ -511,10 +525,14 @@ end
|
|
|
511
525
|
|
|
512
526
|
**NOTE** The ChefSpec server is empty at the start of each example to avoid interdependent tests.
|
|
513
527
|
|
|
528
|
+
### Data Store
|
|
529
|
+
|
|
530
|
+
The `ServerRunner` has two options for how it will store data: `in_memory` or `on_disk`. The default value is `in_memory`. These two options have different performance implications based on your specific setup. If you are running into performance problems (slow tests, frequent hanging, etc) with one setting, try using the other.
|
|
531
|
+
|
|
532
|
+
## Stubbing
|
|
514
533
|
|
|
515
|
-
Stubbing
|
|
516
|
-
--------
|
|
517
534
|
### Command
|
|
535
|
+
|
|
518
536
|
Given a recipe with shell guard:
|
|
519
537
|
|
|
520
538
|
```ruby
|
|
@@ -588,6 +606,7 @@ end
|
|
|
588
606
|
```
|
|
589
607
|
|
|
590
608
|
Stub the output of the library helper. [Additional information](http://jtimberman.housepub.org/blog/2015/05/30/quick-tip-stubbing-library-helpers-in-chefspec/)
|
|
609
|
+
|
|
591
610
|
```ruby
|
|
592
611
|
before do
|
|
593
612
|
allow_any_instance_of(Chef::Node).to receive(:has_bacon?).and_return(true)
|
|
@@ -595,6 +614,7 @@ end
|
|
|
595
614
|
```
|
|
596
615
|
|
|
597
616
|
### Data Bag & Data Bag Item
|
|
617
|
+
|
|
598
618
|
**NOTE** This is not required if you are using a ChefSpec server.
|
|
599
619
|
|
|
600
620
|
Given a recipe that executes a `data_bag` method:
|
|
@@ -653,6 +673,7 @@ end
|
|
|
653
673
|
```
|
|
654
674
|
|
|
655
675
|
### Search
|
|
676
|
+
|
|
656
677
|
**NOTE** This is not required if you are using a ChefSpec server.
|
|
657
678
|
|
|
658
679
|
Because ChefSpec is a unit-testing framework, it is recommended that all third-party API calls be mocked or stubbed. ChefSpec exposes a helpful RSpec macro for stubbing search results in your tests. If you converge a Chef recipe that implements a `search` call, ChefSpec will throw an error like:
|
|
@@ -689,9 +710,8 @@ describe 'example::default' do
|
|
|
689
710
|
end
|
|
690
711
|
```
|
|
691
712
|
|
|
713
|
+
## Reporting
|
|
692
714
|
|
|
693
|
-
Reporting
|
|
694
|
-
---------
|
|
695
715
|
ChefSpec can generate a report of resources read over resources tested.
|
|
696
716
|
|
|
697
717
|
To generate the coverage report, add the following to your `spec_helper.rb` before you require any "Chef" code:
|
|
@@ -754,7 +774,7 @@ For more complex scenarios, you can create a custom `Filter` object that inherit
|
|
|
754
774
|
|
|
755
775
|
```ruby
|
|
756
776
|
class CustomFilter < ChefSpec::Coverage::Filter
|
|
757
|
-
def initialize(arg1, arg2,
|
|
777
|
+
def initialize(arg1, arg2, █)
|
|
758
778
|
# Create a custom initialization method, do some magic, etc.
|
|
759
779
|
end
|
|
760
780
|
|
|
@@ -786,7 +806,8 @@ ChefSpec::Coverage.start! do
|
|
|
786
806
|
set_template 'json.erb'
|
|
787
807
|
end
|
|
788
808
|
```
|
|
789
|
-
|
|
809
|
+
|
|
810
|
+
Provided templates are human.erb_(default)_, table.erb and json.erb, to supply a custom template, specify a relative(to run directory) or absolute path.
|
|
790
811
|
|
|
791
812
|
```ruby
|
|
792
813
|
ChefSpec::Coverage.start! do
|
|
@@ -794,9 +815,28 @@ ChefSpec::Coverage.start! do
|
|
|
794
815
|
end
|
|
795
816
|
```
|
|
796
817
|
|
|
797
|
-
|
|
798
|
-
|
|
818
|
+
If you would like to add alternative reporting for the Coverage.report! ouput, you can supply your own by calling add_output in the `ChefSepc::Coverage` block:
|
|
819
|
+
Note the reportOutput has the following items in it: total, touched, coverage and collections of untouched_resources and all_resources
|
|
820
|
+
|
|
821
|
+
```ruby
|
|
822
|
+
ChefSpec::Coverage.start! do
|
|
823
|
+
add_output do |reportOutput|
|
|
824
|
+
File.open( "coverage.json","w" ) do |f|
|
|
825
|
+
f.puts(reportOutput[:total])
|
|
826
|
+
f.puts(reportOutput[:touched])
|
|
827
|
+
f.puts(reportOutput[:coverage])
|
|
828
|
+
f.puts(reportOutput[:untouched_resources])
|
|
829
|
+
f.puts(reportOutput[:all_resources])
|
|
830
|
+
end
|
|
831
|
+
end
|
|
832
|
+
end
|
|
833
|
+
```
|
|
834
|
+
Note the above example outputs the raw data without applying formatting.
|
|
835
|
+
|
|
836
|
+
## Mocking Out Environments
|
|
837
|
+
|
|
799
838
|
### ServerRunner
|
|
839
|
+
|
|
800
840
|
```ruby
|
|
801
841
|
ChefSpec::ServerRunner.new do |node, server|
|
|
802
842
|
# Create the environment
|
|
@@ -808,6 +848,7 @@ end
|
|
|
808
848
|
```
|
|
809
849
|
|
|
810
850
|
### SoloRunner
|
|
851
|
+
|
|
811
852
|
If you want to mock out `node.chef_environment`, you'll need to use RSpec mocks/stubs twice:
|
|
812
853
|
|
|
813
854
|
```ruby
|
|
@@ -828,9 +869,8 @@ end
|
|
|
828
869
|
|
|
829
870
|
**There is probably a better/easier way to do this. If you have a better solution, please open an issue or Pull Request so we can make this less painful :)**
|
|
830
871
|
|
|
872
|
+
## Testing LWRPs
|
|
831
873
|
|
|
832
|
-
Testing LWRPs
|
|
833
|
-
-------------
|
|
834
874
|
**WARNING** Cookbooks with dashes (hyphens) are difficult to test with ChefSpec because of how Chef classifies objects. We recommend naming cookbooks with underscores (`_`) instead of dashes (`-`).
|
|
835
875
|
|
|
836
876
|
ChefSpec overrides all providers to take no action (otherwise it would actually converge your system). This means that the steps inside your LWRP are not actually executed. If an LWRP performs actions, those actions are never executed or added to the resource collection.
|
|
@@ -853,9 +893,8 @@ end
|
|
|
853
893
|
|
|
854
894
|
**NOTE:** If your cookbook exposes LWRPs, it is highly recommended you also create a `libraries/matchers.rb` file as outlined below in the "Packaging Custom Matchers" section. **You should never `step_into` an LWRP unless you are testing it. Never `step_into` an LWRP from another cookbook!**
|
|
855
895
|
|
|
896
|
+
## Packaging Custom Matchers
|
|
856
897
|
|
|
857
|
-
Packaging Custom Matchers
|
|
858
|
-
-------------------------
|
|
859
898
|
ChefSpec exposes the ability for cookbook authors to package custom matchers inside a cookbook so that other developers may take advantage of them in testing. This is done by creating a special library file in the cookbook named `matchers.rb`:
|
|
860
899
|
|
|
861
900
|
```ruby
|
|
@@ -876,13 +915,15 @@ end
|
|
|
876
915
|
```
|
|
877
916
|
|
|
878
917
|
3. `ChefSpec::Matchers::ResourceMatcher` accepts three parameters:
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
918
|
+
|
|
919
|
+
1. The name of the resource to find in the resource collection (i.e. the name of the LWRP).
|
|
920
|
+
2. The action that resource should receive.
|
|
921
|
+
3. The value of the name attribute of the resource to find. (This is typically proxied as the value from the matcher definition.)
|
|
882
922
|
|
|
883
923
|
ChefSpec's built-in `ResourceMatcher` _should_ satisfy most common use cases for packaging a custom matcher with your LWRPs. However, if your cookbook is extending Chef core or is outside of the scope of a traditional "resource", you may need to create a custom matcher. For more information on custom matchers in RSpec, please [watch the Railscast on Custom Matchers](http://railscasts.com/episodes/157-rspec-matchers-macros) or look at some of the other custom matchers in ChefSpec's source code.
|
|
884
924
|
|
|
885
|
-
|
|
925
|
+
### Example
|
|
926
|
+
|
|
886
927
|
Suppose I have a cookbook named "motd" with a resource/provider "message".
|
|
887
928
|
|
|
888
929
|
```ruby
|
|
@@ -950,9 +991,8 @@ end
|
|
|
950
991
|
|
|
951
992
|
Notice that we have changed the name of the method to match the "foobar" action, but the resource matcher definition remains unchanged. When the Chef run executes, the resource will be inserted into the collection as `motd_message`, even though it was given a custom provides.
|
|
952
993
|
|
|
994
|
+
## Writing Custom Matchers
|
|
953
995
|
|
|
954
|
-
Writing Custom Matchers
|
|
955
|
-
-----------------------
|
|
956
996
|
If you are testing a cookbook that does not package its LWRP matchers, you can create your own following the same pattern as the "Packaging Custom Matchers" section. Simply, create a file at `spec/support/matchers.rb` and add your resource matchers:
|
|
957
997
|
|
|
958
998
|
```ruby
|
|
@@ -970,6 +1010,8 @@ require_relative 'support/matchers'
|
|
|
970
1010
|
|
|
971
1011
|
Please use this as a _temporary_ solution. Consider sending a Pull Request to the LWRP author(s) packaging the custom resource matchers (see previous section).
|
|
972
1012
|
|
|
1013
|
+
## Matchers for looking up custom resources
|
|
1014
|
+
|
|
973
1015
|
ChefSpec also provides a helper method to define a method on the Chef runner for locating a resource in the collection. This is helpful while asserting against custom resource notifications.
|
|
974
1016
|
|
|
975
1017
|
```ruby
|
|
@@ -988,9 +1030,10 @@ it 'notifies the thing' do
|
|
|
988
1030
|
end
|
|
989
1031
|
```
|
|
990
1032
|
|
|
1033
|
+
You can use this functionality to bundle lookup matchers with cookbooks, or to provide your own when the upstream cookbook doesn't include it.
|
|
1034
|
+
|
|
1035
|
+
## Expecting Exceptions
|
|
991
1036
|
|
|
992
|
-
Expecting Exceptions
|
|
993
|
-
--------------------
|
|
994
1037
|
In Chef 11, custom formatters were introduced and ChefSpec uses a custom formatter to suppress Chef Client output. In the event of a convergence failure, ChefSpec will output the error message from the run to help you debug:
|
|
995
1038
|
|
|
996
1039
|
```text
|
|
@@ -1041,8 +1084,8 @@ it 'raises an error' do
|
|
|
1041
1084
|
end
|
|
1042
1085
|
```
|
|
1043
1086
|
|
|
1044
|
-
Testing Multiple Recipes
|
|
1045
|
-
|
|
1087
|
+
## Testing Multiple Recipes
|
|
1088
|
+
|
|
1046
1089
|
Even though ChefSpec is cookbook-centric, you can still converge multiple recipes in a single `ChefSpec::SoloRunner` instance. Given a cookbook "sandwich" with recipes "bacon", "lettuce" and "tomato":
|
|
1047
1090
|
|
|
1048
1091
|
```ruby
|
|
@@ -1066,8 +1109,8 @@ expect(chef_run).to install_package('lettuce')
|
|
|
1066
1109
|
expect(chef_run).to install_package('tomato')
|
|
1067
1110
|
```
|
|
1068
1111
|
|
|
1069
|
-
Testing Roles
|
|
1070
|
-
|
|
1112
|
+
## Testing Roles
|
|
1113
|
+
|
|
1071
1114
|
Roles can also be used in a single `ChefSpec::SoloRunner` instance. Given a cookbook "bacon" with a default recipe:
|
|
1072
1115
|
|
|
1073
1116
|
```ruby
|
|
@@ -1126,9 +1169,8 @@ end
|
|
|
1126
1169
|
ChefSpec::SoloRunner.new(role_path: '/var/my/roles') # local setting
|
|
1127
1170
|
```
|
|
1128
1171
|
|
|
1172
|
+
## Faster Specs
|
|
1129
1173
|
|
|
1130
|
-
Faster Specs
|
|
1131
|
-
------------
|
|
1132
1174
|
ChefSpec aims to provide the easiest and simplest path for new users to write RSpec examples for Chef cookbooks. In doing so, it makes some sacrifices in terms of speed and agility of execution. In other words, ChefSpec favors "speed to develop" over "speed to execute". Many of these decisions are directly related to the way Chef dynamically loads resources at runtime.
|
|
1133
1175
|
|
|
1134
1176
|
If you understand how RSpec works and would like to see some significant speed improvements in your specs, you can use the `ChefSpec::Cacher` module inspired by [Juri Timošin](https://github.com/DracoAter). Simply convert all your `let` blocks to `cached`:
|
|
@@ -1143,9 +1185,8 @@ cached(:chef_run) { ChefSpec::SoloRunner.new }
|
|
|
1143
1185
|
|
|
1144
1186
|
Everything else should work the same. Be advised, as the method name suggests, this will cache the results of your Chef Client Run for the **entire RSpec example**. This makes stubbing more of a challenge, since the node is already converged. For more information, please see [Juri Timošin's blog post on faster specs](http://dracoater.blogspot.com/2013/12/testing-chef-cookbooks-part-25-speeding.html) as well as the discussion in [#275](https://github.com/sethvargo/chefspec/issues/275).
|
|
1145
1187
|
|
|
1188
|
+
## Media & Third-party Tutorials
|
|
1146
1189
|
|
|
1147
|
-
Media & Third-party Tutorials
|
|
1148
|
-
-----------------------------
|
|
1149
1190
|
- [CustomInk's Testing Chef Cookbooks](http://technology.customink.com/blog/2012/08/03/testing-chef-cookbooks/)
|
|
1150
1191
|
- [Jake Vanderdray's Practical ChefSpec](http://files.meetup.com/1780846/ChefSpec.pdf)
|
|
1151
1192
|
- [Jim Hopp's excellent Test Driven Development for Chef Practitioners](http://www.youtube.com/watch?v=o2e0aZUAVGw)
|
|
@@ -1155,9 +1196,8 @@ Media & Third-party Tutorials
|
|
|
1155
1196
|
- [Seth Vargo's TDDing tmux talk](http://www.confreaks.com/videos/2364-mwrc2013-tdding-tmux)
|
|
1156
1197
|
- [Stephen Nelson Smith's Test-Driven Infrastructure with Chef](http://shop.oreilly.com/product/0636920030973.do)
|
|
1157
1198
|
|
|
1199
|
+
## Development
|
|
1158
1200
|
|
|
1159
|
-
Development
|
|
1160
|
-
-----------
|
|
1161
1201
|
1. Fork the repository from GitHub.
|
|
1162
1202
|
2. Clone your fork to your local machine:
|
|
1163
1203
|
|
|
@@ -1172,16 +1212,19 @@ Development
|
|
|
1172
1212
|
```
|
|
1173
1213
|
|
|
1174
1214
|
4. **Write tests**
|
|
1215
|
+
|
|
1175
1216
|
5. Make your changes/patches/fixes, committing appropriately
|
|
1217
|
+
|
|
1176
1218
|
6. Run the tests: `bundle exec rake`
|
|
1219
|
+
|
|
1177
1220
|
7. Push your changes to GitHub
|
|
1221
|
+
|
|
1178
1222
|
8. Open a Pull Request
|
|
1179
1223
|
|
|
1180
|
-
ChefSpec is on [Travis CI]
|
|
1224
|
+
ChefSpec is on [Travis CI][travis] which tests against multiple Chef and Ruby versions.
|
|
1181
1225
|
|
|
1182
1226
|
If you are contributing, please see the [Contributing Guidelines](https://github.com/sethvargo/chefspec/blob/master/CONTRIBUTING.md) for more information.
|
|
1183
1227
|
|
|
1228
|
+
## License
|
|
1184
1229
|
|
|
1185
|
-
License
|
|
1186
|
-
-------
|
|
1187
1230
|
MIT - see the accompanying [LICENSE](https://github.com/sethvargo/chefspec/blob/master/LICENSE) file for details.
|
data/chefspec.gemspec
CHANGED
|
@@ -23,15 +23,14 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
24
24
|
s.require_paths = ['lib']
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
s.required_ruby_version = '>= 2.1'
|
|
26
|
+
s.required_ruby_version = '>= 2.2'
|
|
28
27
|
|
|
29
|
-
s.add_dependency 'chef', '>= 12.
|
|
30
|
-
s.add_dependency 'fauxhai', '
|
|
28
|
+
s.add_dependency 'chef', '>= 12.14.89'
|
|
29
|
+
s.add_dependency 'fauxhai', '>= 4', '< 6'
|
|
31
30
|
s.add_dependency 'rspec', '~> 3.0'
|
|
32
31
|
|
|
33
32
|
# Development Dependencies
|
|
34
|
-
s.add_development_dependency 'rake', '<
|
|
33
|
+
s.add_development_dependency 'rake', '< 13.0'
|
|
35
34
|
s.add_development_dependency 'redcarpet', '~> 3.3'
|
|
36
35
|
s.add_development_dependency 'yard', '~> 0.8'
|
|
37
36
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
require 'chefspec'
|
|
2
2
|
|
|
3
3
|
describe 'apt_package::install' do
|
|
4
|
-
let(:chef_run)
|
|
4
|
+
let(:chef_run) do
|
|
5
|
+
ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
|
|
6
|
+
.converge(described_recipe)
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
it 'installs a apt_package with the default action' do
|
|
7
10
|
expect(chef_run).to install_apt_package('default_action')
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
require 'chefspec'
|
|
2
2
|
|
|
3
3
|
describe 'apt_package::purge' do
|
|
4
|
-
let(:chef_run)
|
|
4
|
+
let(:chef_run) do
|
|
5
|
+
ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
|
|
6
|
+
.converge(described_recipe)
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
it 'purges a apt_package with an explicit action' do
|
|
7
10
|
expect(chef_run).to purge_apt_package('explicit_action')
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
require 'chefspec'
|
|
2
2
|
|
|
3
3
|
describe 'apt_package::reconfig' do
|
|
4
|
-
let(:chef_run)
|
|
4
|
+
let(:chef_run) do
|
|
5
|
+
ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
|
|
6
|
+
.converge(described_recipe)
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
it 'reconfigs a apt_package with an explicit action' do
|
|
7
10
|
expect(chef_run).to reconfig_apt_package('explicit_action')
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
require 'chefspec'
|
|
2
2
|
|
|
3
3
|
describe 'apt_package::remove' do
|
|
4
|
-
let(:chef_run)
|
|
4
|
+
let(:chef_run) do
|
|
5
|
+
ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
|
|
6
|
+
.converge(described_recipe)
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
it 'removes a apt_package with an explicit action' do
|
|
7
10
|
expect(chef_run).to remove_apt_package('explicit_action')
|