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,134 @@
|
|
1
|
+
require "chef/version"
|
2
|
+
|
3
|
+
module ChefSpec
|
4
|
+
module API
|
5
|
+
module StubsFor
|
6
|
+
# Pull in the needed machinery to use `before` here.
|
7
|
+
extend RSpec::SharedContext
|
8
|
+
|
9
|
+
# Which version to use the shell_out_compacted hook on.
|
10
|
+
HAS_SHELLOUT_COMPACTED = Gem::Requirement.create("> 14.2")
|
11
|
+
|
12
|
+
# Hook used in the monkey patches to set up a place to inject stubs when
|
13
|
+
# needed for a resource or provider.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
# @param object [Chef::Resource, Chef::Provider] Resource or provider to inject
|
17
|
+
# @param type [Symbol] Type of object to register stubs on
|
18
|
+
# @return [void]
|
19
|
+
def self.setup_stubs_for(object, type)
|
20
|
+
# This space left intentionally blank, real implementation is below.
|
21
|
+
end
|
22
|
+
|
23
|
+
# Place to hold any stubs which should be active for this example.
|
24
|
+
let(:_chefspec_stubs_for_registry) do
|
25
|
+
# Auto-vivify for things like _chefspec_stubs_for_registry[:resource]['my_resource'] == [].
|
26
|
+
Hash.new do |hash, key|
|
27
|
+
hash[key] = Hash.new do |inner_hash, inner_key|
|
28
|
+
inner_hash[inner_key] = []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Take over from the default, no-op implementation of {.setup_stubs_for}.
|
34
|
+
before do
|
35
|
+
allow(StubsFor).to receive(:setup_stubs_for) do |object, type|
|
36
|
+
type_stubs = _chefspec_stubs_for_registry[type]
|
37
|
+
resource_object = object.is_a?(Chef::Provider) ? object.new_resource : object
|
38
|
+
stubs = type_stubs[nil] + type_stubs[resource_object.resource_name.to_s] + type_stubs[resource_object.to_s]
|
39
|
+
stubs.each do |stub|
|
40
|
+
instance_exec(object, &stub)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Register stubs for resource objects.
|
46
|
+
#
|
47
|
+
# The `target` parameter can select either a resource string like `'package[foo]'`,
|
48
|
+
# a resource name like `'package'`, or `nil` for all resources.
|
49
|
+
#
|
50
|
+
# @example Setting method stub on a single resource
|
51
|
+
# it "does a thing" do
|
52
|
+
# stubs_for_resource("my_resource[foo]") do |res|
|
53
|
+
# expect(res).to receive_shell_out.with("my_command").and_return(stdout: "asdf")
|
54
|
+
# end
|
55
|
+
# expect(subject.some_method).to eq "asdf"
|
56
|
+
# end
|
57
|
+
# @param target [String, nil] Resource name to inject, or nil for all resources.
|
58
|
+
# @param current_resource [Boolean] If true, also register stubs for current_resource objects on the same target.
|
59
|
+
# @param block [Proc] A block taking the resource object as a parameter.
|
60
|
+
# @return [void]
|
61
|
+
def stubs_for_resource(target=nil, current_resource: true, &block)
|
62
|
+
_chefspec_stubs_for_registry[:resource][target] << block
|
63
|
+
stubs_for_current_resource(target, &block) if current_resource
|
64
|
+
end
|
65
|
+
|
66
|
+
# Register stubs for current_resource objects.
|
67
|
+
#
|
68
|
+
# @see #stubs_for_resource
|
69
|
+
# @param target [String, nil] Resource name to inject, or nil for all resources.
|
70
|
+
# @param block [Proc] A block taking the resource object as a parameter.
|
71
|
+
# @return [void]
|
72
|
+
def stubs_for_current_resource(target=nil, &block)
|
73
|
+
_chefspec_stubs_for_registry[:current_resource][target] << block
|
74
|
+
end
|
75
|
+
|
76
|
+
# Register stubs for provider objects.
|
77
|
+
#
|
78
|
+
# @see #stubs_for_resource
|
79
|
+
# @param target [String, nil] Resource name to inject, or nil for all providers.
|
80
|
+
# @param block [Proc] A block taking the resource object as a parameter.
|
81
|
+
# @return [void]
|
82
|
+
def stubs_for_provider(target=nil, &block)
|
83
|
+
_chefspec_stubs_for_registry[:provider][target] << block
|
84
|
+
end
|
85
|
+
|
86
|
+
def receive_shell_out(*cmd, stdout: '', stderr: '', exitstatus: 0, **opts)
|
87
|
+
# Ruby does not allow constructing an actual exitstatus object from Ruby code. Really.
|
88
|
+
fake_exitstatus = double(exitstatus: exitstatus)
|
89
|
+
fake_cmd = Mixlib::ShellOut.new(*cmd, **opts)
|
90
|
+
fake_cmd.define_singleton_method(:run_command) { } # Do nothing, just in case.
|
91
|
+
# Inject our canned data.
|
92
|
+
fake_cmd.instance_exec do
|
93
|
+
@stdout = stdout
|
94
|
+
@stderr = stderr
|
95
|
+
@status = fake_exitstatus
|
96
|
+
end
|
97
|
+
# On newer Chef, we can intercept using the new, better shell_out_compact hook point.
|
98
|
+
shell_out_method ||= if HAS_SHELLOUT_COMPACTED.satisfied_by?(Gem::Version.create(Chef::VERSION))
|
99
|
+
:shell_out_compacted
|
100
|
+
else
|
101
|
+
:shell_out
|
102
|
+
end
|
103
|
+
receive(shell_out_method).with(*cmd).and_return(fake_cmd)
|
104
|
+
end
|
105
|
+
|
106
|
+
module ClassMethods
|
107
|
+
# (see StubsFor#stubs_for_resource)
|
108
|
+
def stubs_for_resource(*args, &block)
|
109
|
+
before { stubs_for_resource(*args, &block) }
|
110
|
+
end
|
111
|
+
|
112
|
+
# (see StubsFor#stubs_for_current_resource)
|
113
|
+
def stubs_for_current_resource(*args, &block)
|
114
|
+
before { stubs_for_current_resource(*args, &block) }
|
115
|
+
end
|
116
|
+
|
117
|
+
# (see StubsFor#stubs_for_provider)
|
118
|
+
def stubs_for_provider(*args, &block)
|
119
|
+
before { stubs_for_provider(*args, &block) }
|
120
|
+
end
|
121
|
+
|
122
|
+
# @api private
|
123
|
+
def included(klass)
|
124
|
+
super
|
125
|
+
# Inject classmethods into the group.
|
126
|
+
klass.extend(ClassMethods)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
extend ClassMethods
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -1,32 +1,37 @@
|
|
1
|
-
module ChefSpec
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
module ChefSpec
|
2
|
+
module API
|
3
|
+
module Subscriptions
|
4
|
+
#
|
5
|
+
# Assert that a resource subscribes to another. Given a Chef Recipe that
|
6
|
+
# subscribes a template resource to restart apache:
|
7
|
+
#
|
8
|
+
# service 'apache2' do
|
9
|
+
# subscribes :create, 'template[/etc/apache2/config]'
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# The Examples section demonstrates the different ways to test a
|
13
|
+
# subscription on a resource with ChefSpec.
|
14
|
+
#
|
15
|
+
# @example Assert a basic subscription
|
16
|
+
# service = chef_run.service('apache2')
|
17
|
+
# expect(service).to subscribe_to('template[/etc/apache2/config]')
|
18
|
+
#
|
19
|
+
# @example Assert a subscription with specified action
|
20
|
+
# expect(service).to subscribe_to('template[/etc/apache2/config]').on(:restart)
|
21
|
+
#
|
22
|
+
# @example Assert a subscription with specified action and timing
|
23
|
+
# expect(service).to subscribe_to('template[/etc/apache2/config]').on(:restart).immediately
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# @param [String] signature
|
27
|
+
# the signature of the notification to match
|
28
|
+
#
|
29
|
+
# @return [ChefSpec::Matchers::NotificationsMatcher]
|
30
|
+
#
|
31
|
+
def subscribe_to(signature)
|
32
|
+
ChefSpec::Matchers::SubscribesMatcher.new(signature)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
data/lib/chefspec/api/user.rb
CHANGED
@@ -1,225 +1,230 @@
|
|
1
|
-
module ChefSpec
|
2
|
-
|
1
|
+
module ChefSpec
|
2
|
+
module API
|
3
|
+
module User
|
4
|
+
ChefSpec.define_matcher :user
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
6
|
+
#
|
7
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "apache2" as a
|
9
|
+
# +user+:
|
10
|
+
#
|
11
|
+
# user 'apache2' do
|
12
|
+
# action :create
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# The Examples section demonstrates the different ways to test a
|
16
|
+
# +user+ resource with ChefSpec.
|
17
|
+
#
|
18
|
+
# @example Assert that a +user+ was created
|
19
|
+
# expect(chef_run).to create_user('apache2')
|
20
|
+
#
|
21
|
+
# @example Assert that a +user+ was created with predicate matchers
|
22
|
+
# expect(chef_run).to create_user('apache2').with_uid(1234)
|
23
|
+
#
|
24
|
+
# @example Assert that a +user+ was created with attributes
|
25
|
+
# expect(chef_run).to create_user('apache2').with(uid: 1234)
|
26
|
+
#
|
27
|
+
# @example Assert that a +user+ was created using a regex
|
28
|
+
# expect(chef_run).to create_user('apache2').with(uid: /\d+/)
|
29
|
+
#
|
30
|
+
# @example Assert that a +user+ was _not_ created
|
31
|
+
# expect(chef_run).to_not create_user('apache2')
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# @param [String, Regex] resource_name
|
35
|
+
# the name of the resource to match
|
36
|
+
#
|
37
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
38
|
+
#
|
39
|
+
def create_user(resource_name)
|
40
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :create, resource_name)
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
43
|
+
#
|
44
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
45
|
+
# action +:remove+. Given a Chef Recipe that removes "apache2" as a
|
46
|
+
# +user+:
|
47
|
+
#
|
48
|
+
# user 'apache2' do
|
49
|
+
# action :remove
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# The Examples section demonstrates the different ways to test a
|
53
|
+
# +user+ resource with ChefSpec.
|
54
|
+
#
|
55
|
+
# @example Assert that a +user+ was remove
|
56
|
+
# expect(chef_run).to remove_user('apache2')
|
57
|
+
#
|
58
|
+
# @example Assert that a +user+ was remove with predicate matchers
|
59
|
+
# expect(chef_run).to remove_user('apache2').with_uid(1234)
|
60
|
+
#
|
61
|
+
# @example Assert that a +user+ was remove with attributes
|
62
|
+
# expect(chef_run).to remove_user('apache2').with(uid: 1234)
|
63
|
+
#
|
64
|
+
# @example Assert that a +user+ was remove using a regex
|
65
|
+
# expect(chef_run).to remove_user('apache2').with(uid: /\d+/)
|
66
|
+
#
|
67
|
+
# @example Assert that a +user+ was _not_ remove
|
68
|
+
# expect(chef_run).to_not remove_user('apache2')
|
69
|
+
#
|
70
|
+
#
|
71
|
+
# @param [String, Regex] resource_name
|
72
|
+
# the name of the resource to match
|
73
|
+
#
|
74
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
75
|
+
#
|
76
|
+
def remove_user(resource_name)
|
77
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :remove, resource_name)
|
78
|
+
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
80
|
+
#
|
81
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
82
|
+
# action +:modify+. Given a Chef Recipe that modifies "apache2" as a
|
83
|
+
# +user+:
|
84
|
+
#
|
85
|
+
# user 'apache2' do
|
86
|
+
# action :modify
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# The Examples section demonstrates the different ways to test a
|
90
|
+
# +user+ resource with ChefSpec.
|
91
|
+
#
|
92
|
+
# @example Assert that a +user+ was modified
|
93
|
+
# expect(chef_run).to modify_user('apache2')
|
94
|
+
#
|
95
|
+
# @example Assert that a +user+ was modified with predicate matchers
|
96
|
+
# expect(chef_run).to modify_user('apache2').with_uid(1234)
|
97
|
+
#
|
98
|
+
# @example Assert that a +user+ was modified with attributes
|
99
|
+
# expect(chef_run).to modify_user('apache2').with(uid: 1234)
|
100
|
+
#
|
101
|
+
# @example Assert that a +user+ was modified using a regex
|
102
|
+
# expect(chef_run).to modify_user('apache2').with(uid: /\d+/)
|
103
|
+
#
|
104
|
+
# @example Assert that a +user+ was _not_ modified
|
105
|
+
# expect(chef_run).to_not modify_user('apache2')
|
106
|
+
#
|
107
|
+
#
|
108
|
+
# @param [String, Regex] resource_name
|
109
|
+
# the name of the resource to match
|
110
|
+
#
|
111
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
112
|
+
#
|
113
|
+
def modify_user(resource_name)
|
114
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :modify, resource_name)
|
115
|
+
end
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
117
|
+
#
|
118
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
119
|
+
# action +:manage+. Given a Chef Recipe that manages "apache2" as a
|
120
|
+
# +user+:
|
121
|
+
#
|
122
|
+
# user 'apache2' do
|
123
|
+
# action :manage
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# The Examples section demonstrates the different ways to test a
|
127
|
+
# +user+ resource with ChefSpec.
|
128
|
+
#
|
129
|
+
# @example Assert that a +user+ was managed
|
130
|
+
# expect(chef_run).to manage_user('apache2')
|
131
|
+
#
|
132
|
+
# @example Assert that a +user+ was managed with predicate matchers
|
133
|
+
# expect(chef_run).to manage_user('apache2').with_uid(1234)
|
134
|
+
#
|
135
|
+
# @example Assert that a +user+ was managed with attributes
|
136
|
+
# expect(chef_run).to manage_user('apache2').with(uid: 1234)
|
137
|
+
#
|
138
|
+
# @example Assert that a +user+ was managed using a regex
|
139
|
+
# expect(chef_run).to manage_user('apache2').with(uid: /\d+/)
|
140
|
+
#
|
141
|
+
# @example Assert that a +user+ was _not_ managed
|
142
|
+
# expect(chef_run).to_not manage_user('apache2')
|
143
|
+
#
|
144
|
+
#
|
145
|
+
# @param [String, Regex] resource_name
|
146
|
+
# the name of the resource to match
|
147
|
+
#
|
148
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
149
|
+
#
|
150
|
+
def manage_user(resource_name)
|
151
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :manage, resource_name)
|
152
|
+
end
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
154
|
+
#
|
155
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
156
|
+
# action +:lock+. Given a Chef Recipe that locks "apache2" as a
|
157
|
+
# +user+:
|
158
|
+
#
|
159
|
+
# user 'apache2' do
|
160
|
+
# action :lock
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# The Examples section demonstrates the different ways to test a
|
164
|
+
# +user+ resource with ChefSpec.
|
165
|
+
#
|
166
|
+
# @example Assert that a +user+ was locked
|
167
|
+
# expect(chef_run).to lock_user('apache2')
|
168
|
+
#
|
169
|
+
# @example Assert that a +user+ was locked with predicate matchers
|
170
|
+
# expect(chef_run).to lock_user('apache2').with_uid(1234)
|
171
|
+
#
|
172
|
+
# @example Assert that a +user+ was locked with attributes
|
173
|
+
# expect(chef_run).to lock_user('apache2').with(uid: 1234)
|
174
|
+
#
|
175
|
+
# @example Assert that a +user+ was locked using a regex
|
176
|
+
# expect(chef_run).to lock_user('apache2').with(uid: /\d+/)
|
177
|
+
#
|
178
|
+
# @example Assert that a +user+ was _not_ locked
|
179
|
+
# expect(chef_run).to_not lock_user('apache2')
|
180
|
+
#
|
181
|
+
#
|
182
|
+
# @param [String, Regex] resource_name
|
183
|
+
# the name of the resource to match
|
184
|
+
#
|
185
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
186
|
+
#
|
187
|
+
def lock_user(resource_name)
|
188
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :lock, resource_name)
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
193
|
+
# action +:unlock+. Given a Chef Recipe that unlocks "apache2" as a
|
194
|
+
# +user+:
|
195
|
+
#
|
196
|
+
# user 'apache2' do
|
197
|
+
# action :unlock
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# The Examples section demonstrates the different ways to test a
|
201
|
+
# +user+ resource with ChefSpec.
|
202
|
+
#
|
203
|
+
# @example Assert that a +user+ was unlocked
|
204
|
+
# expect(chef_run).to unlock_user('apache2')
|
205
|
+
#
|
206
|
+
# @example Assert that a +user+ was unlocked with predicate matchers
|
207
|
+
# expect(chef_run).to unlock_user('apache2').with_uid(1234)
|
208
|
+
#
|
209
|
+
# @example Assert that a +user+ was unlocked with attributes
|
210
|
+
# expect(chef_run).to unlock_user('apache2').with(uid: 1234)
|
211
|
+
#
|
212
|
+
# @example Assert that a +user+ was unlocked using a regex
|
213
|
+
# expect(chef_run).to unlock_user('apache2').with(uid: /\d+/)
|
214
|
+
#
|
215
|
+
# @example Assert that a +user+ was _not_ unlocked
|
216
|
+
# expect(chef_run).to_not unlock_user('apache2')
|
217
|
+
#
|
218
|
+
#
|
219
|
+
# @param [String, Regex] resource_name
|
220
|
+
# the name of the resource to match
|
221
|
+
#
|
222
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
223
|
+
#
|
224
|
+
def unlock_user(resource_name)
|
225
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :unlock, resource_name)
|
226
|
+
end
|
188
227
|
|
189
|
-
|
190
|
-
# Assert that a +user+ resource exists in the Chef run with the
|
191
|
-
# action +:unlock+. Given a Chef Recipe that unlocks "apache2" as a
|
192
|
-
# +user+:
|
193
|
-
#
|
194
|
-
# user 'apache2' do
|
195
|
-
# action :unlock
|
196
|
-
# end
|
197
|
-
#
|
198
|
-
# The Examples section demonstrates the different ways to test a
|
199
|
-
# +user+ resource with ChefSpec.
|
200
|
-
#
|
201
|
-
# @example Assert that a +user+ was unlocked
|
202
|
-
# expect(chef_run).to unlock_user('apache2')
|
203
|
-
#
|
204
|
-
# @example Assert that a +user+ was unlocked with predicate matchers
|
205
|
-
# expect(chef_run).to unlock_user('apache2').with_uid(1234)
|
206
|
-
#
|
207
|
-
# @example Assert that a +user+ was unlocked with attributes
|
208
|
-
# expect(chef_run).to unlock_user('apache2').with(uid: 1234)
|
209
|
-
#
|
210
|
-
# @example Assert that a +user+ was unlocked using a regex
|
211
|
-
# expect(chef_run).to unlock_user('apache2').with(uid: /\d+/)
|
212
|
-
#
|
213
|
-
# @example Assert that a +user+ was _not_ unlocked
|
214
|
-
# expect(chef_run).to_not unlock_user('apache2')
|
215
|
-
#
|
216
|
-
#
|
217
|
-
# @param [String, Regex] resource_name
|
218
|
-
# the name of the resource to match
|
219
|
-
#
|
220
|
-
# @return [ChefSpec::Matchers::ResourceMatcher]
|
221
|
-
#
|
222
|
-
def unlock_user(resource_name)
|
223
|
-
ChefSpec::Matchers::ResourceMatcher.new(:user, :unlock, resource_name)
|
228
|
+
end
|
224
229
|
end
|
225
230
|
end
|