chefspec 4.0.2 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +19 -0
- data/README.md +84 -87
- data/chefspec.gemspec +1 -1
- data/examples/apt_package/spec/install_spec.rb +1 -1
- data/examples/apt_package/spec/purge_spec.rb +1 -1
- data/examples/apt_package/spec/reconfig_spec.rb +1 -1
- data/examples/apt_package/spec/remove_spec.rb +1 -1
- data/examples/apt_package/spec/upgrade_spec.rb +1 -1
- data/examples/attributes/spec/default_spec.rb +1 -1
- data/examples/batch/spec/run_spec.rb +1 -1
- data/examples/cached/spec/default_spec.rb +1 -1
- data/examples/chef_gem/spec/install_spec.rb +1 -1
- data/examples/chef_gem/spec/purge_spec.rb +1 -1
- data/examples/chef_gem/spec/reconfig_spec.rb +1 -1
- data/examples/chef_gem/spec/remove_spec.rb +1 -1
- data/examples/chef_gem/spec/upgrade_spec.rb +1 -1
- data/examples/compile_time/spec/default_spec.rb +1 -1
- data/examples/cookbook_file/spec/create_if_missing_spec.rb +1 -1
- data/examples/cookbook_file/spec/create_spec.rb +1 -1
- data/examples/cookbook_file/spec/delete_spec.rb +1 -1
- data/examples/cookbook_file/spec/touch_spec.rb +1 -1
- data/examples/cron/spec/create_spec.rb +1 -1
- data/examples/cron/spec/delete_spec.rb +1 -1
- data/examples/custom_matcher/libraries/matcher.rb +1 -1
- data/examples/custom_matcher/spec/install_spec.rb +1 -1
- data/examples/custom_matcher/spec/remove_spec.rb +1 -1
- data/examples/deploy/spec/deploy_spec.rb +1 -1
- data/examples/deploy/spec/force_deploy_spec.rb +1 -1
- data/examples/deploy/spec/rollback_spec.rb +1 -1
- data/examples/directory/spec/create_spec.rb +1 -1
- data/examples/directory/spec/delete_spec.rb +1 -1
- data/examples/do_nothing/spec/default_spec.rb +1 -1
- data/examples/dpkg_package/spec/install_spec.rb +1 -1
- data/examples/dpkg_package/spec/purge_spec.rb +1 -1
- data/examples/dpkg_package/spec/remove_spec.rb +1 -1
- data/examples/easy_install_package/spec/install_spec.rb +1 -1
- data/examples/easy_install_package/spec/purge_spec.rb +1 -1
- data/examples/easy_install_package/spec/remove_spec.rb +1 -1
- data/examples/easy_install_package/spec/upgrade_spec.rb +1 -1
- data/examples/env/spec/create_spec.rb +1 -1
- data/examples/env/spec/delete_spec.rb +1 -1
- data/examples/env/spec/modify_spec.rb +1 -1
- data/examples/erl_call/spec/run_spec.rb +1 -1
- data/examples/execute/spec/run_spec.rb +1 -1
- data/examples/expect_exception/spec/compile_error_spec.rb +1 -1
- data/examples/expect_exception/spec/converge_error_spec.rb +1 -1
- data/examples/expect_exception/spec/no_error_spec.rb +1 -1
- data/examples/file/spec/create_if_missing_spec.rb +1 -1
- data/examples/file/spec/create_spec.rb +1 -1
- data/examples/file/spec/delete_spec.rb +1 -1
- data/examples/file/spec/touch_spec.rb +1 -1
- data/examples/freebsd_package/spec/install_spec.rb +1 -1
- data/examples/freebsd_package/spec/remove_spec.rb +1 -1
- data/examples/gem_package/spec/install_spec.rb +1 -1
- data/examples/gem_package/spec/purge_spec.rb +1 -1
- data/examples/gem_package/spec/reconfig_spec.rb +1 -1
- data/examples/gem_package/spec/remove_spec.rb +1 -1
- data/examples/gem_package/spec/upgrade_spec.rb +1 -1
- data/examples/git/spec/checkout_spec.rb +1 -1
- data/examples/git/spec/export_spec.rb +1 -1
- data/examples/git/spec/sync_spec.rb +1 -1
- data/examples/group/spec/create_spec.rb +1 -1
- data/examples/group/spec/manage_spec.rb +1 -1
- data/examples/group/spec/modify_spec.rb +1 -1
- data/examples/group/spec/remove_spec.rb +1 -1
- data/examples/guards/spec/default_spec.rb +1 -1
- data/examples/heavy_provider_light_resource/spec/provider_service_spec.rb +1 -1
- data/examples/http_request/spec/delete_spec.rb +1 -1
- data/examples/http_request/spec/get_spec.rb +1 -1
- data/examples/http_request/spec/head_spec.rb +1 -1
- data/examples/http_request/spec/options_spec.rb +1 -1
- data/examples/http_request/spec/post_spec.rb +1 -1
- data/examples/http_request/spec/put_spec.rb +1 -1
- data/examples/ifconfig/spec/add_spec.rb +1 -1
- data/examples/ifconfig/spec/delete_spec.rb +1 -1
- data/examples/ifconfig/spec/disable_spec.rb +1 -1
- data/examples/ifconfig/spec/enable_spec.rb +1 -1
- data/examples/include_recipe/spec/default_spec.rb +1 -1
- data/examples/inherits/spec/default_spec.rb +1 -1
- data/examples/ips_package/spec/install_spec.rb +1 -1
- data/examples/ips_package/spec/remove_spec.rb +1 -1
- data/examples/ips_package/spec/upgrade_spec.rb +1 -1
- data/examples/link/spec/create_spec.rb +1 -1
- data/examples/link/spec/delete_spec.rb +1 -1
- data/examples/link/spec/link_to_spec.rb +1 -1
- data/examples/log/spec/write_spec.rb +1 -1
- data/examples/macports_package/spec/install_spec.rb +1 -1
- data/examples/macports_package/spec/purge_spec.rb +1 -1
- data/examples/macports_package/spec/remove_spec.rb +1 -1
- data/examples/macports_package/spec/upgrade_spec.rb +1 -1
- data/examples/mdadm/spec/assemble_spec.rb +1 -1
- data/examples/mdadm/spec/create_spec.rb +1 -1
- data/examples/mdadm/spec/stop_spec.rb +1 -1
- data/examples/mount/spec/disable_spec.rb +1 -1
- data/examples/mount/spec/enable_spec.rb +1 -1
- data/examples/mount/spec/mount_spec.rb +1 -1
- data/examples/mount/spec/remount_spec.rb +1 -1
- data/examples/mount/spec/umount_spec.rb +1 -1
- data/examples/multiple_actions/spec/default_spec.rb +1 -1
- data/examples/multiple_actions/spec/sequential_spec.rb +4 -1
- data/examples/multiple_run_action/spec/default_spec.rb +1 -1
- data/examples/notifications/spec/chained_spec.rb +1 -1
- data/examples/notifications/spec/default_spec.rb +1 -1
- data/examples/notifications/spec/delayed_spec.rb +1 -1
- data/examples/notifications/spec/immediately_spec.rb +1 -1
- data/examples/ohai/spec/reload_spec.rb +1 -1
- data/examples/package/spec/install_spec.rb +1 -1
- data/examples/package/spec/purge_spec.rb +1 -1
- data/examples/package/spec/reconfig_spec.rb +1 -1
- data/examples/package/spec/remove_spec.rb +1 -1
- data/examples/package/spec/upgrade_spec.rb +1 -1
- data/examples/pacman_package/spec/install_spec.rb +1 -1
- data/examples/pacman_package/spec/purge_spec.rb +1 -1
- data/examples/pacman_package/spec/remove_spec.rb +1 -1
- data/examples/pacman_package/spec/upgrade_spec.rb +1 -1
- data/examples/portage_package/spec/install_spec.rb +1 -1
- data/examples/portage_package/spec/purge_spec.rb +1 -1
- data/examples/portage_package/spec/remove_spec.rb +1 -1
- data/examples/portage_package/spec/upgrade_spec.rb +1 -1
- data/examples/powershell_script/spec/run_spec.rb +1 -1
- data/examples/registry_key/spec/create_if_missing_spec.rb +1 -1
- data/examples/registry_key/spec/create_spec.rb +1 -1
- data/examples/registry_key/spec/delete_key_spec.rb +1 -1
- data/examples/registry_key/spec/delete_spec.rb +1 -1
- data/examples/remote_directory/spec/create_if_missing_spec.rb +1 -1
- data/examples/remote_directory/spec/create_spec.rb +1 -1
- data/examples/remote_directory/spec/delete_spec.rb +1 -1
- data/examples/remote_file/spec/create_if_missing_spec.rb +1 -1
- data/examples/remote_file/spec/create_spec.rb +1 -1
- data/examples/remote_file/spec/delete_spec.rb +1 -1
- data/examples/remote_file/spec/touch_spec.rb +1 -1
- data/examples/render_file/spec/default_spec.rb +1 -1
- data/examples/render_file/spec/template_helpers_spec.rb +1 -1
- data/examples/roles/spec/default_spec.rb +1 -1
- data/examples/route/spec/add_spec.rb +1 -1
- data/examples/route/spec/delete_spec.rb +1 -1
- data/examples/rpm_package/spec/install_spec.rb +1 -1
- data/examples/rpm_package/spec/remove_spec.rb +1 -1
- data/examples/rpm_package/spec/upgrade_spec.rb +1 -1
- data/examples/ruby_block/spec/run_spec.rb +1 -1
- data/examples/script/spec/run_bash_spec.rb +1 -1
- data/examples/script/spec/run_csh_spec.rb +1 -1
- data/examples/script/spec/run_perl_spec.rb +1 -1
- data/examples/script/spec/run_python_spec.rb +1 -1
- data/examples/script/spec/run_ruby_spec.rb +1 -1
- data/examples/script/spec/run_script_spec.rb +1 -1
- data/examples/server/spec/client_spec.rb +5 -4
- data/examples/server/spec/data_bag_spec.rb +10 -9
- data/examples/server/spec/environment_spec.rb +5 -4
- data/examples/server/spec/node_spec.rb +20 -14
- data/examples/server/spec/render_with_cached_spec.rb +1 -2
- data/examples/server/spec/role_spec.rb +5 -4
- data/examples/server/spec/search_spec.rb +7 -8
- data/examples/service/spec/disable_spec.rb +1 -1
- data/examples/service/spec/enable_spec.rb +1 -1
- data/examples/service/spec/reload_spec.rb +1 -1
- data/examples/service/spec/restart_spec.rb +1 -1
- data/examples/service/spec/start_spec.rb +1 -1
- data/examples/service/spec/stop_spec.rb +1 -1
- data/examples/smartos_package/spec/install_spec.rb +1 -1
- data/examples/smartos_package/spec/remove_spec.rb +1 -1
- data/examples/smartos_package/spec/upgrade_spec.rb +1 -1
- data/examples/solaris_package/spec/install_spec.rb +1 -1
- data/examples/solaris_package/spec/remove_spec.rb +1 -1
- data/examples/state_attrs/spec/default_spec.rb +2 -2
- data/examples/step_into/spec/default_spec.rb +5 -2
- data/examples/stub_command/spec/default_spec.rb +1 -1
- data/examples/stub_data_bag/spec/default_spec.rb +1 -1
- data/examples/stub_data_bag_item/spec/default_spec.rb +1 -1
- data/examples/stub_search/spec/default_spec.rb +1 -1
- data/examples/subscribes/spec/chained_spec.rb +1 -1
- data/examples/subscribes/spec/default_spec.rb +1 -1
- data/examples/subscribes/spec/delayed_spec.rb +1 -1
- data/examples/subscribes/spec/immediately_spec.rb +1 -1
- data/examples/subversion/spec/checkout_spec.rb +1 -1
- data/examples/subversion/spec/export_spec.rb +1 -1
- data/examples/subversion/spec/force_export_spec.rb +1 -1
- data/examples/subversion/spec/sync_spec.rb +1 -1
- data/examples/template/spec/create_if_missing_spec.rb +1 -1
- data/examples/template/spec/create_spec.rb +1 -1
- data/examples/template/spec/delete_spec.rb +1 -1
- data/examples/template/spec/touch_spec.rb +1 -1
- data/examples/use_inline_resources/spec/default_spec.rb +4 -1
- data/examples/user/spec/create_spec.rb +1 -1
- data/examples/user/spec/lock_spec.rb +1 -1
- data/examples/user/spec/manage_spec.rb +1 -1
- data/examples/user/spec/modify_spec.rb +1 -1
- data/examples/user/spec/remove_spec.rb +1 -1
- data/examples/user/spec/unlock_spec.rb +1 -1
- data/examples/yum_package/spec/install_spec.rb +1 -1
- data/examples/yum_package/spec/purge_spec.rb +1 -1
- data/examples/yum_package/spec/remove_spec.rb +1 -1
- data/examples/yum_package/spec/upgrade_spec.rb +1 -1
- data/features/batch.feature +0 -3
- data/features/powershell_script.feature +0 -3
- data/features/render_file.feature +1 -6
- data/features/server.feature +0 -3
- data/features/smartos_package.feature +0 -4
- data/features/solaris_package.feature +0 -4
- data/features/state_attrs.feature +0 -4
- data/features/support/env.rb +0 -7
- data/gemfiles/{chef-11.12.0.gemfile → chef-11.16.0.gemfile} +1 -1
- data/gemfiles/chef-12.0.0.alpha.gemfile +5 -0
- data/lib/chefspec.rb +46 -14
- data/lib/chefspec/api.rb +0 -2
- data/lib/chefspec/api/apt_package.rb +1 -1
- data/lib/chefspec/api/batch.rb +1 -1
- data/lib/chefspec/api/chef_gem.rb +1 -1
- data/lib/chefspec/api/cookbook_file.rb +1 -1
- data/lib/chefspec/api/cron.rb +1 -1
- data/lib/chefspec/api/deploy.rb +1 -1
- data/lib/chefspec/api/directory.rb +1 -1
- data/lib/chefspec/api/dpkg_package.rb +1 -1
- data/lib/chefspec/api/easy_install_package.rb +1 -1
- data/lib/chefspec/api/env.rb +1 -1
- data/lib/chefspec/api/erl_call.rb +1 -1
- data/lib/chefspec/api/execute.rb +1 -1
- data/lib/chefspec/api/file.rb +1 -1
- data/lib/chefspec/api/freebsd_package.rb +1 -1
- data/lib/chefspec/api/gem_package.rb +1 -1
- data/lib/chefspec/api/git.rb +1 -1
- data/lib/chefspec/api/group.rb +1 -1
- data/lib/chefspec/api/http_request.rb +1 -1
- data/lib/chefspec/api/ifconfig.rb +1 -1
- data/lib/chefspec/api/ips_package.rb +1 -1
- data/lib/chefspec/api/link.rb +1 -1
- data/lib/chefspec/api/log.rb +1 -1
- data/lib/chefspec/api/macports_package.rb +1 -1
- data/lib/chefspec/api/mdadm.rb +1 -1
- data/lib/chefspec/api/mount.rb +1 -1
- data/lib/chefspec/api/ohai.rb +2 -2
- data/lib/chefspec/api/package.rb +1 -1
- data/lib/chefspec/api/pacman_package.rb +1 -1
- data/lib/chefspec/api/portage_package.rb +1 -1
- data/lib/chefspec/api/powershell_script.rb +1 -1
- data/lib/chefspec/api/registry_key.rb +1 -1
- data/lib/chefspec/api/remote_directory.rb +4 -4
- data/lib/chefspec/api/remote_file.rb +1 -1
- data/lib/chefspec/api/route.rb +1 -1
- data/lib/chefspec/api/rpm_package.rb +1 -1
- data/lib/chefspec/api/ruby_block.rb +1 -1
- data/lib/chefspec/api/script.rb +6 -6
- data/lib/chefspec/api/service.rb +1 -1
- data/lib/chefspec/api/smartos_package.rb +1 -1
- data/lib/chefspec/api/solaris_package.rb +1 -1
- data/lib/chefspec/api/subversion.rb +1 -1
- data/lib/chefspec/api/template.rb +1 -1
- data/lib/chefspec/api/user.rb +1 -1
- data/lib/chefspec/api/yum_package.rb +1 -1
- data/lib/chefspec/coverage/filters.rb +3 -0
- data/lib/chefspec/deprecations.rb +19 -123
- data/lib/chefspec/macros.rb +2 -2
- data/lib/chefspec/matchers/render_file_matcher.rb +2 -2
- data/lib/chefspec/matchers/resource_matcher.rb +1 -1
- data/lib/chefspec/matchers/state_attrs_matcher.rb +1 -1
- data/lib/chefspec/server.rb +4 -361
- data/lib/chefspec/server_methods.rb +175 -0
- data/lib/chefspec/server_runner.rb +86 -0
- data/lib/chefspec/{runner.rb → solo_runner.rb} +92 -43
- data/lib/chefspec/version.rb +1 -1
- data/spec/unit/{runner_spec.rb → solo_runner_spec.rb} +31 -25
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f7f37a530acbb9dff67aed530b585d77fdd0775
|
4
|
+
data.tar.gz: 33079e8115211a7bb28392ea9aa26a584f2b8e43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62f881a2f5ca9f7438399dfba1925ea5226c742c6e3d7da85facf1df9be28a8444d799c18428af6e0d9e12288a259a64fe3af47905733ca83572b28b33c92ac2
|
7
|
+
data.tar.gz: 4ee3f4f55710eca0bc4bf036ec683306a1d9312583ebe9edbfd3dfef892d5224813586c6109be50e0af4b89d0a393095b8e263d1fc46ab5e108319989f6c445b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
CHANGELOG for ChefSpec
|
2
2
|
======================
|
3
3
|
|
4
|
+
## 4.1.0 (October 12, 2014)
|
5
|
+
Bugfixes:
|
6
|
+
- Bump the minimum required version of Chef to 11.14
|
7
|
+
- Filter resources that have no source line in the coverage report - this is related to a bug in Chef where, when cloning a resource, both the clone and the original resource lose their metadata
|
8
|
+
|
9
|
+
Improvements:
|
10
|
+
- Allow multiple instances of a Chef Server instance
|
11
|
+
- Separate ChefSpec::Runner into `ChefSpec::SoloRunner` and `ChefSpec::ServerRunner`
|
12
|
+
- Preliminary support for Chef 12 alpha (not 100% complete)
|
13
|
+
- Add `SoloRunner` and `ServerRunner` `.converge` methods for quickly converging if you do not need to customize the runner object
|
14
|
+
- Create isolated Chef Server instances on a per-test or per-suite basis
|
15
|
+
- Deprecate `ChefSpec::Runner.define_runner_method` in favor of `ChefSpec.define_matcher`
|
16
|
+
- Deprecate `ChefSpec::Runner.new` - you should specify if you want a `SoloRunner` or `ServerRunner`
|
17
|
+
- Updated documentation
|
18
|
+
|
19
|
+
Breaking changes:
|
20
|
+
- Due to the new `ServerRunner`, the `ChefSpec::Server` singleton object has been deprecated. As much as I would like to provide a backwards-compatible interface, there is no way to do so (as the code now supports multipel Chef Server instances). Sorry :(.
|
21
|
+
- Remove old deprecations - this is not really a breaking change, but the v2.0.0 deprecations have been removed in favor of new ones
|
22
|
+
|
4
23
|
## 4.0.2 (August 13, 2014)
|
5
24
|
Bugfixes:
|
6
25
|
- Fix a regression caused by a new version of Chef Zero in single_org mode
|
data/README.md
CHANGED
@@ -4,17 +4,15 @@ ChefSpec
|
|
4
4
|
[![Build Status](http://img.shields.io/travis/sethvargo/chefspec.svg)][travis]
|
5
5
|
[![Dependency Status](http://img.shields.io/gemnasium/sethvargo/chefspec.svg)][gemnasium]
|
6
6
|
[![Code Climate](http://img.shields.io/codeclimate/github/sethvargo/chefspec.svg)][codeclimate]
|
7
|
-
[![Gittip](http://img.shields.io/gittip/sethvargo.svg)][gittip]
|
8
7
|
|
9
8
|
[gem]: https://rubygems.org/gems/chefspec
|
10
9
|
[travis]: http://travis-ci.org/sethvargo/chefspec
|
11
10
|
[gemnasium]: https://gemnasium.com/sethvargo/chefspec
|
12
11
|
[codeclimate]: https://codeclimate.com/github/sethvargo/chefspec
|
13
|
-
[gittip]: https://www.gittip.com/sethvargo
|
14
12
|
|
15
13
|
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.
|
16
14
|
|
17
|
-
ChefSpec runs your cookbook locally
|
15
|
+
ChefSpec runs your cookbook(s) locally with Chef Solo without actually converging a node. This has two primary benefits:
|
18
16
|
|
19
17
|
- It's really fast!
|
20
18
|
- Your tests can vary node attributes, operating systems, and search results to assert behavior under varying conditions.
|
@@ -24,27 +22,17 @@ What people are saying
|
|
24
22
|
----------------------
|
25
23
|
> I just wanted to drop you a line to say "HELL YES!" to ChefSpec. - [Joe Goggins](https://twitter.com/jgoggins)
|
26
24
|
|
27
|
-
> OK
|
25
|
+
> OK ChefSpec is my new best friend. Delightful few hours working with it. - [Michael Ivey](https://twitter.com/ivey)
|
28
26
|
|
29
27
|
**Chat with us - [#chefspec](irc://irc.freenode.net/chefspec) on Freenode**
|
30
28
|
|
31
29
|
|
32
30
|
Important Notes
|
33
31
|
---------------
|
34
|
-
- **ChefSpec 3 requires
|
35
|
-
- **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' documentation!**
|
32
|
+
- **ChefSpec 3.0+ requires Ruby 1.9 or higher!**
|
33
|
+
- **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!**
|
36
34
|
- **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).**
|
37
|
-
- **ChefSpec
|
38
|
-
|
39
|
-
If you are migrating from ChefSpec v2.0.0, you should require the deprecations module after requiring `chefspec`:
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
# spec_helper.rb
|
43
|
-
require 'chefspec'
|
44
|
-
require 'chefspec/deprecations'
|
45
|
-
```
|
46
|
-
|
47
|
-
After you have converted your specs, you can safely remove the deprecations module.
|
35
|
+
- **ChefSpec aims to maintain compatability 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.
|
48
36
|
|
49
37
|
|
50
38
|
Writing a Cookbook Example
|
@@ -63,7 +51,7 @@ the associated ChefSpec test might look like:
|
|
63
51
|
require 'chefspec'
|
64
52
|
|
65
53
|
describe 'example::default' do
|
66
|
-
let(:chef_run) { ChefSpec::
|
54
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
67
55
|
|
68
56
|
it 'installs foo' do
|
69
57
|
expect(chef_run).to install_package('foo')
|
@@ -107,23 +95,23 @@ RSpec.configure do |config|
|
|
107
95
|
end
|
108
96
|
```
|
109
97
|
|
110
|
-
Values specified at the initialization of
|
98
|
+
Values specified at the initialization of a "Runner" merge and take precedence over any global settings:
|
111
99
|
|
112
100
|
```ruby
|
113
101
|
# Override only the operating system version (platform is still "ubuntu" from above)
|
114
|
-
ChefSpec::
|
102
|
+
ChefSpec::SoloRunner.new(version: '10.04')
|
115
103
|
|
116
104
|
# Use a different operating system platform and version
|
117
|
-
ChefSpec::
|
105
|
+
ChefSpec::SoloRunner.new(platform: 'centos', version: '5.10')
|
118
106
|
|
119
107
|
# Specify a different cookbook_path
|
120
|
-
ChefSpec::
|
108
|
+
ChefSpec::SoloRunner.new(cookbook_path: '/var/my/other/path', role_path: '/var/my/roles')
|
121
109
|
|
122
110
|
# Add debug log output
|
123
|
-
ChefSpec::
|
111
|
+
ChefSpec::SoloRunner.new(log_level: :debug).converge(described_recipe)
|
124
112
|
```
|
125
113
|
|
126
|
-
**NOTE** You do not _need_ to specify a platform and version. However, some cookbooks may rely on [Ohai](http://github.com/opscode/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).
|
114
|
+
**NOTE** You do not _need_ to specify a platform and version to use ChefSpec. However, some cookbooks may rely on [Ohai](http://github.com/opscode/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).
|
127
115
|
|
128
116
|
### Berkshelf
|
129
117
|
If you are using Berkshelf, simply require `chefspec/berkshelf` in your `spec_helper` after requiring `chefspec`:
|
@@ -169,7 +157,7 @@ cookbook 'name_of_your_cookbook', path: '.'
|
|
169
157
|
|
170
158
|
Running Specs
|
171
159
|
-------------
|
172
|
-
ChefSpec is actually
|
160
|
+
ChefSpec is actually an RSpec extension, so you can run your tests using the RSpec CLI:
|
173
161
|
|
174
162
|
```bash
|
175
163
|
$ rspec
|
@@ -192,7 +180,7 @@ ChefSpec asserts that resource actions have been performed. In general, ChefSpec
|
|
192
180
|
require 'chefspec'
|
193
181
|
|
194
182
|
describe 'example::default' do
|
195
|
-
let(:chef_run) { ChefSpec::
|
183
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
196
184
|
|
197
185
|
it 'does something' do
|
198
186
|
expect(chef_run).to ACTION_RESOURCE(NAME)
|
@@ -206,13 +194,15 @@ where:
|
|
206
194
|
- _RESOURCE_ - the name of the resource (e.g. `package`)
|
207
195
|
- _NAME_ - the name attribute for the resource (e.g. `apache2`)
|
208
196
|
|
197
|
+
**NOTE** One exception to this rule is the `create_if_missing` action on the `file` resource. In this case the assertion is actually `create_file_if_missing`. Refer to `examples/file/spec/create_if_missing_spec.rb` for some examples.
|
198
|
+
|
209
199
|
Here's a more concrete example:
|
210
200
|
|
211
201
|
```ruby
|
212
202
|
require 'chefspec'
|
213
203
|
|
214
204
|
describe 'example::default' do
|
215
|
-
let(:chef_run) { ChefSpec::
|
205
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
216
206
|
|
217
207
|
it 'does something' do
|
218
208
|
expect(chef_run).to install_package('apache2')
|
@@ -228,7 +218,7 @@ To test that a resource action is performed with a specific set of attributes, y
|
|
228
218
|
require 'chefspec'
|
229
219
|
|
230
220
|
describe 'example::default' do
|
231
|
-
let(:chef_run) { ChefSpec::
|
221
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
232
222
|
|
233
223
|
it 'does something' do
|
234
224
|
expect(chef_run).to modify_group('docker').with(members: ['vagrant'])
|
@@ -318,7 +308,7 @@ Node attribute can be set when creating the `Runner`. The initializer yields a b
|
|
318
308
|
```ruby
|
319
309
|
describe 'example::default' do
|
320
310
|
let(:chef_run) do
|
321
|
-
ChefSpec::
|
311
|
+
ChefSpec::SoloRunner.new do |node|
|
322
312
|
node.set['cookbook']['attribute'] = 'hello'
|
323
313
|
end.converge(described_recipe)
|
324
314
|
end
|
@@ -331,7 +321,7 @@ ChefSpec provides mocked automatic Ohai data using [fauxhai](https://github.com/
|
|
331
321
|
```ruby
|
332
322
|
describe 'example::default' do
|
333
323
|
let(:chef_run) do
|
334
|
-
ChefSpec::
|
324
|
+
ChefSpec::SoloRunner.new do |node|
|
335
325
|
node.automatic['memory']['total'] = '512kB'
|
336
326
|
end.converge(described_recipe)
|
337
327
|
end
|
@@ -344,7 +334,7 @@ To set an attribute within a specific test, set the attribute in the `it` block
|
|
344
334
|
|
345
335
|
```ruby
|
346
336
|
describe 'example::default' do
|
347
|
-
let(:chef_run) { ChefSpec::
|
337
|
+
let(:chef_run) { ChefSpec::SoloRunner.new } # Notice we don't converge here
|
348
338
|
|
349
339
|
it 'performs the action' do
|
350
340
|
chef_run.node.set['cookbook']['attribute'] = 'hello'
|
@@ -355,19 +345,20 @@ describe 'example::default' do
|
|
355
345
|
end
|
356
346
|
```
|
357
347
|
|
358
|
-
Using Chef
|
359
|
-
|
360
|
-
|
348
|
+
Using a Chef Server
|
349
|
+
-------------------
|
350
|
+
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.
|
361
351
|
|
362
|
-
To use the ChefSpec server, simply
|
352
|
+
To use the ChefSpec server, simply replace `ChefSpec::SoloRunner` with `ChefSpec::ServerRunner`:
|
363
353
|
|
364
|
-
```
|
365
|
-
|
366
|
-
|
367
|
-
|
354
|
+
```diff
|
355
|
+
describe 'example::default' do
|
356
|
+
- let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
|
357
|
+
+ let(:chef_run) { ChefSpec::ServerRunner.converge(described_recipe) }
|
358
|
+
end
|
368
359
|
```
|
369
360
|
|
370
|
-
This will automatically create a Chef
|
361
|
+
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.
|
371
362
|
|
372
363
|
### DSL
|
373
364
|
The ChefSpec server includes a collection of helpful DSL methods for populating data into the Chef Server.
|
@@ -375,58 +366,68 @@ The ChefSpec server includes a collection of helpful DSL methods for populating
|
|
375
366
|
Create a client:
|
376
367
|
|
377
368
|
```ruby
|
378
|
-
ChefSpec::
|
369
|
+
ChefSpec::ServerRunner.new do |node, server|
|
370
|
+
server.create_client('my_client', { admin: true })
|
371
|
+
end
|
379
372
|
```
|
380
373
|
|
381
374
|
Create a data bag (and items):
|
382
375
|
|
383
376
|
```ruby
|
384
|
-
ChefSpec::
|
385
|
-
'
|
386
|
-
'
|
387
|
-
|
388
|
-
|
389
|
-
'
|
390
|
-
|
391
|
-
}
|
377
|
+
ChefSpec::ServerRunner.new do |node, server|
|
378
|
+
server.create_data_bag('my_data_bag', {
|
379
|
+
'item_1' => {
|
380
|
+
'password' => 'abc123'
|
381
|
+
},
|
382
|
+
'item_2' => {
|
383
|
+
'password' => 'def456'
|
384
|
+
}
|
385
|
+
})
|
386
|
+
end
|
392
387
|
```
|
393
388
|
|
394
389
|
Create an environment:
|
395
390
|
|
396
391
|
```ruby
|
397
|
-
ChefSpec::
|
392
|
+
ChefSpec::ServerRunner.new do |node, server|
|
393
|
+
server.create_environment('my_environment', { description: '...' })
|
394
|
+
end
|
398
395
|
```
|
399
396
|
|
400
397
|
Create a node:
|
401
398
|
|
402
399
|
```ruby
|
403
|
-
ChefSpec::
|
400
|
+
ChefSpec::ServerRunner.new do |node, server|
|
401
|
+
server.create_node('my_node', { run_list: ['...'] })
|
402
|
+
end
|
404
403
|
```
|
405
404
|
|
406
|
-
|
405
|
+
Note: the current "node" is always uploaded to the server.
|
406
|
+
|
407
|
+
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:
|
407
408
|
|
408
409
|
```ruby
|
409
410
|
www = stub_node(platform: 'ubuntu', version: '12.04') do |node|
|
410
411
|
node.set['attribute'] = 'value'
|
411
412
|
end
|
412
413
|
|
413
|
-
# `www` is now a local Chef::Node object you can use in your test. To
|
414
|
-
# node to the server, call `create_node`:
|
414
|
+
# `www` is now a local Chef::Node object you can use in your test. To publish
|
415
|
+
# this node to the server, call `create_node`:
|
415
416
|
|
416
|
-
ChefSpec::
|
417
|
+
ChefSpec::ServerRunner.new do |node, server|
|
418
|
+
server.create_node(www)
|
419
|
+
end
|
417
420
|
```
|
418
421
|
|
419
422
|
Create a role:
|
420
423
|
|
421
424
|
```ruby
|
422
|
-
ChefSpec::
|
423
|
-
|
424
|
-
|
425
|
-
# by adding it to the `converge` block:
|
426
|
-
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe, 'role[my_role]') }
|
425
|
+
ChefSpec::ServerRunner.new do |node, server|
|
426
|
+
server.create_role('my_role', { default_attributes: {} })
|
427
|
+
end
|
427
428
|
```
|
428
429
|
|
429
|
-
**NOTE** The ChefSpec server is empty at the start of each example to avoid interdependent tests.
|
430
|
+
**NOTE** The ChefSpec server is empty at the start of each example to avoid interdependent tests.
|
430
431
|
|
431
432
|
|
432
433
|
Stubbing
|
@@ -456,7 +457,7 @@ Just like the error message says, you must stub the command result. This can be
|
|
456
457
|
|
457
458
|
```ruby
|
458
459
|
describe 'example::default' do
|
459
|
-
let(:chef_run) { ChefSpec::
|
460
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
460
461
|
|
461
462
|
before do
|
462
463
|
stub_command("grep /tmp/foo.txt text").and_return(true)
|
@@ -466,7 +467,7 @@ end
|
|
466
467
|
|
467
468
|
```ruby
|
468
469
|
describe 'example::default' do
|
469
|
-
let(:chef_run) { ChefSpec::
|
470
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
470
471
|
|
471
472
|
before do
|
472
473
|
stub_command("grep /tmp/foo.txt text") { rand(50)%2 == 0 }
|
@@ -501,7 +502,7 @@ Just like the error message says, you must stub the result of the `data_bag` cal
|
|
501
502
|
|
502
503
|
```ruby
|
503
504
|
describe 'example::default' do
|
504
|
-
let(:chef_run) { ChefSpec::
|
505
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
505
506
|
|
506
507
|
before do
|
507
508
|
stub_data_bag('users').and_return([])
|
@@ -511,7 +512,7 @@ end
|
|
511
512
|
|
512
513
|
```ruby
|
513
514
|
describe 'example::default' do
|
514
|
-
let(:chef_run) { ChefSpec::
|
515
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
515
516
|
|
516
517
|
before do
|
517
518
|
stub_data_bag('users').and_return(['svargo', 'francis'])
|
@@ -551,7 +552,7 @@ Just like the error message says, you must stub the search result. This can be d
|
|
551
552
|
|
552
553
|
```ruby
|
553
554
|
describe 'example::default' do
|
554
|
-
let(:chef_run) { ChefSpec::
|
555
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
555
556
|
|
556
557
|
before do
|
557
558
|
stub_search(:node, 'name:hello').and_return([])
|
@@ -561,7 +562,7 @@ end
|
|
561
562
|
|
562
563
|
```ruby
|
563
564
|
describe 'example::default' do
|
564
|
-
let(:chef_run) { ChefSpec::
|
565
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
565
566
|
|
566
567
|
before do
|
567
568
|
stub_search(:node, 'name:hello') { (ruby_code) }
|
@@ -569,6 +570,7 @@ describe 'example::default' do
|
|
569
570
|
end
|
570
571
|
```
|
571
572
|
|
573
|
+
|
572
574
|
Reporting
|
573
575
|
---------
|
574
576
|
ChefSpec can generate a report of resources read over resources tested.
|
@@ -665,7 +667,7 @@ If you want to mock out `node.chef_environment`, you'll need to use RSpec mocks/
|
|
665
667
|
|
666
668
|
```ruby
|
667
669
|
let(:chef_run) do
|
668
|
-
ChefSpec::
|
670
|
+
ChefSpec::SoloRunner.new do |node|
|
669
671
|
# Create a new environment (you could also use a different :let block or :before block)
|
670
672
|
env = Chef::Environment.new
|
671
673
|
env.name 'staging'
|
@@ -694,7 +696,9 @@ In order to run the actions exposed by your LWRP, you have to explicitly tell th
|
|
694
696
|
require 'chefspec'
|
695
697
|
|
696
698
|
describe 'foo::default' do
|
697
|
-
let(:chef_run)
|
699
|
+
let(:chef_run) do
|
700
|
+
ChefSpec::SoloRunner.new(step_into: ['my_lwrp']).converge('foo::default')
|
701
|
+
end
|
698
702
|
|
699
703
|
it 'installs the foo package through my_lwrp' do
|
700
704
|
expect(chef_run).to install_package('foo')
|
@@ -799,13 +803,13 @@ ChefSpec also provides a helper method to define a method on the Chef runner for
|
|
799
803
|
|
800
804
|
```ruby
|
801
805
|
# matchers.rb
|
802
|
-
ChefSpec
|
806
|
+
ChefSpec.define_matcher :my_custom_resource
|
803
807
|
```
|
804
808
|
|
805
809
|
And then in your spec suite, you can obtain the custom resource for assertions:
|
806
810
|
|
807
811
|
```ruby
|
808
|
-
let(:chef_run) { ChefSpec::
|
812
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge('...') }
|
809
813
|
|
810
814
|
it 'notifies the thing' do
|
811
815
|
custom = chef_run.my_custom_resource('name')
|
@@ -845,7 +849,7 @@ Relevant File Content:
|
|
845
849
|
This output is automatically silenced when using RSpec's `raise_error` matcher:
|
846
850
|
|
847
851
|
```ruby
|
848
|
-
let(:chef_run) { ChefSpec::
|
852
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge('cookbook::recipe') }
|
849
853
|
|
850
854
|
it 'raises an error' do
|
851
855
|
expect {
|
@@ -857,7 +861,7 @@ end
|
|
857
861
|
You can also assert that a particular error was raised. If the error matches the given type, the output is suppressed. If not, the test fails and the entire stack trace is presented.
|
858
862
|
|
859
863
|
```ruby
|
860
|
-
let(:chef_run) { ChefSpec::
|
864
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge('cookbook::recipe') }
|
861
865
|
|
862
866
|
it 'raises an error' do
|
863
867
|
expect {
|
@@ -868,7 +872,7 @@ end
|
|
868
872
|
|
869
873
|
Testing Roles
|
870
874
|
-------------
|
871
|
-
Even though ChefSpec is cookbook-centric, you can still converge multiple recipes and roles in a single `ChefSpec::
|
875
|
+
Even though ChefSpec is cookbook-centric, you can still converge multiple recipes and roles in a single `ChefSpec::SoloRunner` instance. Given a cookbook "bacon" with a default recipe:
|
872
876
|
|
873
877
|
```ruby
|
874
878
|
# cookbooks/bacon/recipes/default.rb
|
@@ -896,10 +900,10 @@ run_list([
|
|
896
900
|
])
|
897
901
|
```
|
898
902
|
|
899
|
-
You can test that the role is appropriately applied by telling the `ChefSpec::
|
903
|
+
You can test that the role is appropriately applied by telling the `ChefSpec::SoloRunner` to converge on the _role_ instead of a recipe:
|
900
904
|
|
901
905
|
```ruby
|
902
|
-
let(:chef_run) { ChefSpec::
|
906
|
+
let(:chef_run) { ChefSpec::SoloRunner.converge('role[breakfast]') }
|
903
907
|
```
|
904
908
|
|
905
909
|
Assert that the run_list is properly expanded:
|
@@ -923,7 +927,7 @@ end
|
|
923
927
|
|
924
928
|
# - OR -
|
925
929
|
|
926
|
-
ChefSpec::
|
930
|
+
ChefSpec::SoloRunner.new(role_path: '/var/my/roles') # local setting
|
927
931
|
```
|
928
932
|
|
929
933
|
|
@@ -931,21 +935,14 @@ Faster Specs
|
|
931
935
|
------------
|
932
936
|
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.
|
933
937
|
|
934
|
-
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).
|
935
|
-
|
936
|
-
```ruby
|
937
|
-
# spec_helper.rb
|
938
|
-
require 'chefspec/cacher'
|
939
|
-
```
|
940
|
-
|
941
|
-
Next, convert all your `let` blocks to `cached`:
|
938
|
+
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`:
|
942
939
|
|
943
940
|
```ruby
|
944
941
|
# before
|
945
|
-
let(:chef_run) { ChefSpec::
|
942
|
+
let(:chef_run) { ChefSpec::SoloRunner.new }
|
946
943
|
|
947
944
|
# after
|
948
|
-
cached(:chef_run) { ChefSpec::
|
945
|
+
cached(:chef_run) { ChefSpec::SoloRunner.new }
|
949
946
|
```
|
950
947
|
|
951
948
|
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).
|