chefspec 5.3.0 → 6.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.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -8
  3. data/CHANGELOG.md +23 -1
  4. data/README.md +94 -69
  5. data/chefspec.gemspec +2 -3
  6. data/examples/apt_package/spec/install_spec.rb +1 -1
  7. data/examples/apt_package/spec/purge_spec.rb +1 -1
  8. data/examples/apt_package/spec/reconfig_spec.rb +1 -1
  9. data/examples/apt_package/spec/remove_spec.rb +1 -1
  10. data/examples/apt_package/spec/upgrade_spec.rb +1 -1
  11. data/examples/apt_repository/spec/add_spec.rb +1 -1
  12. data/examples/apt_repository/spec/remove_spec.rb +1 -1
  13. data/examples/apt_update/spec/periodic_spec.rb +1 -1
  14. data/examples/apt_update/spec/update_spec.rb +1 -1
  15. data/examples/batch/spec/run_spec.rb +1 -1
  16. data/examples/cab_package/recipes/install.rb +13 -0
  17. data/examples/cab_package/recipes/remove.rb +13 -0
  18. data/examples/cab_package/spec/install_spec.rb +26 -0
  19. data/examples/cab_package/spec/remove_spec.rb +22 -0
  20. data/examples/chocolatey_package/spec/install_spec.rb +1 -1
  21. data/examples/chocolatey_package/spec/remove_spec.rb +1 -1
  22. data/examples/chocolatey_package/spec/upgrade_spec.rb +1 -1
  23. data/examples/dnf_package/recipes/install.rb +13 -0
  24. data/examples/dnf_package/recipes/purge.rb +13 -0
  25. data/examples/dnf_package/recipes/remove.rb +13 -0
  26. data/examples/dnf_package/recipes/upgrade.rb +13 -0
  27. data/examples/dnf_package/spec/install_spec.rb +26 -0
  28. data/examples/dnf_package/spec/purge_spec.rb +22 -0
  29. data/examples/dnf_package/spec/remove_spec.rb +22 -0
  30. data/examples/dnf_package/spec/upgrade_spec.rb +22 -0
  31. data/examples/dpkg_package/spec/install_spec.rb +1 -1
  32. data/examples/dpkg_package/spec/purge_spec.rb +1 -1
  33. data/examples/dpkg_package/spec/remove_spec.rb +1 -1
  34. data/examples/dsc_resource/spec/run_spec.rb +4 -4
  35. data/examples/dsc_script/spec/run_spec.rb +1 -1
  36. data/examples/env/spec/create_spec.rb +1 -1
  37. data/examples/env/spec/delete_spec.rb +1 -1
  38. data/examples/env/spec/modify_spec.rb +1 -1
  39. data/examples/freebsd_package/spec/install_spec.rb +1 -1
  40. data/examples/freebsd_package/spec/remove_spec.rb +1 -1
  41. data/examples/ips_package/spec/install_spec.rb +1 -1
  42. data/examples/ips_package/spec/remove_spec.rb +1 -1
  43. data/examples/ips_package/spec/upgrade_spec.rb +1 -1
  44. data/examples/msu_package/recipes/install.rb +13 -0
  45. data/examples/msu_package/recipes/remove.rb +13 -0
  46. data/examples/msu_package/spec/install_spec.rb +26 -0
  47. data/examples/msu_package/spec/remove_spec.rb +22 -0
  48. data/examples/pacman_package/spec/install_spec.rb +1 -1
  49. data/examples/pacman_package/spec/purge_spec.rb +1 -1
  50. data/examples/pacman_package/spec/remove_spec.rb +1 -1
  51. data/examples/pacman_package/spec/upgrade_spec.rb +1 -1
  52. data/examples/portage_package/spec/install_spec.rb +1 -1
  53. data/examples/portage_package/spec/purge_spec.rb +1 -1
  54. data/examples/portage_package/spec/remove_spec.rb +1 -1
  55. data/examples/portage_package/spec/upgrade_spec.rb +1 -1
  56. data/examples/powershell_script/spec/run_spec.rb +1 -1
  57. data/examples/registry_key/spec/create_if_missing_spec.rb +1 -1
  58. data/examples/registry_key/spec/create_spec.rb +1 -1
  59. data/examples/registry_key/spec/delete_key_spec.rb +1 -1
  60. data/examples/registry_key/spec/delete_spec.rb +1 -1
  61. data/examples/roles/roles/role.rb +2 -2
  62. data/examples/rpm_package/spec/install_spec.rb +1 -1
  63. data/examples/rpm_package/spec/remove_spec.rb +1 -1
  64. data/examples/rpm_package/spec/upgrade_spec.rb +1 -1
  65. data/examples/server/spec/data_bag_spec.rb +9 -11
  66. data/examples/smartos_package/spec/install_spec.rb +1 -1
  67. data/examples/smartos_package/spec/remove_spec.rb +1 -1
  68. data/examples/smartos_package/spec/upgrade_spec.rb +1 -1
  69. data/examples/solaris_package/spec/install_spec.rb +1 -1
  70. data/examples/solaris_package/spec/remove_spec.rb +1 -1
  71. data/examples/step_into/spec/default_spec.rb +2 -2
  72. data/examples/use_inline_resources/spec/default_spec.rb +1 -1
  73. data/examples/windows_package/spec/install_spec.rb +1 -1
  74. data/examples/windows_package/spec/remove_spec.rb +1 -1
  75. data/examples/windows_service/spec/configure_startup_spec.rb +1 -1
  76. data/examples/windows_service/spec/disable_spec.rb +1 -1
  77. data/examples/windows_service/spec/enable_spec.rb +1 -1
  78. data/examples/windows_service/spec/reload_spec.rb +1 -1
  79. data/examples/windows_service/spec/restart_spec.rb +1 -1
  80. data/examples/windows_service/spec/start_spec.rb +1 -1
  81. data/examples/windows_service/spec/stop_spec.rb +1 -1
  82. data/examples/yum_package/spec/install_spec.rb +1 -1
  83. data/examples/yum_package/spec/purge_spec.rb +1 -1
  84. data/examples/yum_package/spec/remove_spec.rb +1 -1
  85. data/examples/yum_package/spec/upgrade_spec.rb +1 -1
  86. data/examples/yum_repository/spec/add_spec.rb +1 -1
  87. data/examples/yum_repository/spec/create_spec.rb +1 -1
  88. data/examples/yum_repository/spec/delete_spec.rb +1 -1
  89. data/examples/yum_repository/spec/makecache_spec.rb +1 -1
  90. data/examples/yum_repository/spec/remove_spec.rb +1 -1
  91. data/features/apt_repository.feature +0 -6
  92. data/features/apt_update.feature +0 -6
  93. data/features/cab_package.feature +21 -0
  94. data/features/chocolatey_package.feature +0 -6
  95. data/features/dnf_package.feature +26 -0
  96. data/features/dsc_resource.feature +0 -3
  97. data/features/launchd.feature +0 -6
  98. data/features/msu_package.feature +23 -0
  99. data/features/notifications.feature +0 -7
  100. data/features/openbsd_package.feature +0 -2
  101. data/features/osx_profile.feature +0 -6
  102. data/features/paludis_package.feature +0 -2
  103. data/features/script.feature +0 -7
  104. data/features/server_on_disk.feature +16 -0
  105. data/features/subscribes.feature +0 -7
  106. data/features/support/env.rb +8 -0
  107. data/features/support/on_disk.rb +7 -0
  108. data/features/systemd_unit.feature +0 -6
  109. data/features/windows_package.feature +0 -5
  110. data/features/yum_repository.feature +0 -6
  111. data/features/zypper_package.feature +0 -5
  112. data/gemfiles/chefspec.gemfile +0 -6
  113. data/lib/chefspec/api/cab_package.rb +80 -0
  114. data/lib/chefspec/api/dnf_package.rb +154 -0
  115. data/lib/chefspec/api/msu_package.rb +81 -0
  116. data/lib/chefspec/api.rb +3 -0
  117. data/lib/chefspec/rspec.rb +2 -0
  118. data/lib/chefspec/server_methods.rb +4 -10
  119. data/lib/chefspec/server_runner.rb +2 -42
  120. data/lib/chefspec/version.rb +1 -1
  121. data/lib/chefspec/zero_server.rb +139 -0
  122. data/lib/chefspec.rb +0 -1
  123. metadata +36 -7
  124. data/lib/chefspec/chef_backwards_compat.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd963cf180a20e6c7271d54e58c941c719052754
4
- data.tar.gz: cc514dca888b1a8c99fcd4e4c917dc56df2ff8e5
3
+ metadata.gz: c39538d26c07878521a8a68a1e8b488c80901e1d
4
+ data.tar.gz: f95025605f2aaa4d047cb2f193fb6575e9e55144
5
5
  SHA512:
6
- metadata.gz: e3cc38869f14061cbe3b2ebaf3f6c46042429925b7495ef55b5471074f23a6afb435dd7aebfad101a4ffa943ef793fb28b176159a3bd5dd390365a3e7cd50e2c
7
- data.tar.gz: 1f5f5cf99b9926d07232b850d195d2817c58200d773ca419e16dd7fe64b9f3f81c93ad5fa931835e2430eb05787a8e4df94f0cc03ecc9fc39b9e4bbfeb58ea03
6
+ metadata.gz: 24ca89915326c5474ed8802aa2d34c5777661e40d2cfcde76ada3ecf44f131968efd41a7c3f373ac41d4b6f6c0b8c4149b24adac82cd937b05541e80487d5a2d
7
+ data.tar.gz: 15caa99f8225ec1f17186bab5d7b895a9a1febdec0c3bc050d2077da69948ef9827fcedd6c46d3812acc5a128bc22e099ae0f2a8fc450ab9308e93bcff272d75
data/.travis.yml CHANGED
@@ -6,8 +6,7 @@ before_install:
6
6
  - gem install bundler
7
7
 
8
8
  rvm:
9
- - 2.1.9
10
- - 2.2.5
9
+ - 2.2.6
11
10
 
12
11
  branches:
13
12
  only:
@@ -19,6 +18,11 @@ gemfile: gemfiles/chefspec.gemfile
19
18
 
20
19
  env:
21
20
  - CHEF_VERSION=master
21
+ - CHEF_VERSION=12.18.31
22
+ - CHEF_VERSION=12.17.44
23
+ - CHEF_VERSION=12.16.42
24
+ - CHEF_VERSION=12.15.19
25
+ - CHEF_VERSION=12.14.89
22
26
  - CHEF_VERSION=12.13.37
23
27
  - CHEF_VERSION=12.12.15
24
28
  - CHEF_VERSION=12.11.18
@@ -27,12 +31,6 @@ env:
27
31
  - CHEF_VERSION=12.8.1
28
32
  - CHEF_VERSION=12.7.2
29
33
  - CHEF_VERSION=12.6.0
30
- - CHEF_VERSION=12.5.1
31
- - CHEF_VERSION=12.4.3
32
- - CHEF_VERSION=12.3.0
33
- - CHEF_VERSION=12.2.1
34
- - CHEF_VERSION=12.1.2
35
- - CHEF_VERSION=12.0.3
36
34
 
37
35
  matrix:
38
36
  fast_finish: true
data/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  # CHANGELOG for ChefSpec
2
2
 
3
- ## 5.3.0 (October 20, 2016)
3
+ ## 6.0.0 (February 22, 2017)
4
+
5
+ BREAKING CHANGES
6
+
7
+ ChefSpec now requires Ruby 2.2 or later.
8
+
9
+ IMPROVEMENTS
10
+
11
+ - Improve ServerRunner speed and reduce process hangs by using a single stand-alone chef-zero server.
12
+ - Add configuration value to dictate whether cookbooks are re-uploaded before every test context.
13
+ - Added matchers for dnf_package, msu_package, and cab_package
14
+
15
+ ## 5.4.0 (February 9, 2017)
16
+
17
+ IMPROVEMENTS
18
+
19
+ - Support for in-memory or on-disk ChefZero Servers. See README for usage details.
20
+
21
+ UPDATES
22
+
23
+ - While Chef 12.0 - 12.5 are still supported, they are no longer being tested.
24
+
25
+ ## 5.3.0 (October 29, 2016)
4
26
 
5
27
  IMPROVEMENTS
6
28
 
data/README.md CHANGED
@@ -1,10 +1,6 @@
1
- ChefSpec
2
- ========
3
- [![Gem Version](http://img.shields.io/gem/v/chefspec.svg)][gem]
4
- [![Build Status](http://img.shields.io/travis/sethvargo/chefspec.svg)][travis]
1
+ # ChefSpec
5
2
 
6
- [gem]: https://rubygems.org/gems/chefspec
7
- [travis]: http://travis-ci.org/sethvargo/chefspec
3
+ [![Gem Version](https://badge.fury.io/rb/chefspec.svg)](https://badge.fury.io/rb/chefspec) [![Build Status](https://travis-ci.org/sethvargo/chefspec.svg?branch=master)](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
- Important Notes
27
- ---------------
28
- - **ChefSpec requires Ruby 2.1 or later and Chef 12.0.2 or later!**
22
+ - **ChefSpec requires Ruby 2.1 or later and Chef 12.6 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:
@@ -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
- 1. 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.
69
- 1. The `let` block on creates the `ChefSpec:Runner` and 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.
70
- 1. The `described_recipe` macro is a ChefSpec helper method that infers the recipe from the `describe` block. Alternatively you could specify the recipe directly.
71
- 1. 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.
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:Runner` and 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
@@ -128,7 +119,25 @@ ChefSpec::SoloRunner.new(log_level: :debug).converge(described_recipe)
128
119
 
129
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).
130
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
+ ```
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
- ##### include_recipe
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
- ##### notify
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
- ##### subscribes
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
- ##### render_file
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
- ##### do_nothing
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:
@@ -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, &block)
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
- 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.
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,10 @@ ChefSpec::Coverage.start! do
794
815
  end
795
816
  ```
796
817
 
797
- Mocking Out Environments
798
- ------------------------
818
+ ## Mocking Out Environments
819
+
799
820
  ### ServerRunner
821
+
800
822
  ```ruby
801
823
  ChefSpec::ServerRunner.new do |node, server|
802
824
  # Create the environment
@@ -808,6 +830,7 @@ end
808
830
  ```
809
831
 
810
832
  ### SoloRunner
833
+
811
834
  If you want to mock out `node.chef_environment`, you'll need to use RSpec mocks/stubs twice:
812
835
 
813
836
  ```ruby
@@ -828,9 +851,8 @@ end
828
851
 
829
852
  **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
853
 
854
+ ## Testing LWRPs
831
855
 
832
- Testing LWRPs
833
- -------------
834
856
  **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
857
 
836
858
  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 +875,8 @@ end
853
875
 
854
876
  **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
877
 
878
+ ## Packaging Custom Matchers
856
879
 
857
- Packaging Custom Matchers
858
- -------------------------
859
880
  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
881
 
861
882
  ```ruby
@@ -876,13 +897,15 @@ end
876
897
  ```
877
898
 
878
899
  3. `ChefSpec::Matchers::ResourceMatcher` accepts three parameters:
879
- 1. The name of the resource to find in the resource collection (i.e. the name of the LWRP).
880
- 2. The action that resource should receive.
881
- 3. The value of the name attribute of the resource to find. (This is typically proxied as the value from the matcher definition.)
900
+
901
+ 1. The name of the resource to find in the resource collection (i.e. the name of the LWRP).
902
+ 2. The action that resource should receive.
903
+ 3. The value of the name attribute of the resource to find. (This is typically proxied as the value from the matcher definition.)
882
904
 
883
905
  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
906
 
885
- #### Example
907
+ ### Example
908
+
886
909
  Suppose I have a cookbook named "motd" with a resource/provider "message".
887
910
 
888
911
  ```ruby
@@ -950,9 +973,8 @@ end
950
973
 
951
974
  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
975
 
976
+ ## Writing Custom Matchers
953
977
 
954
- Writing Custom Matchers
955
- -----------------------
956
978
  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
979
 
958
980
  ```ruby
@@ -970,6 +992,8 @@ require_relative 'support/matchers'
970
992
 
971
993
  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
994
 
995
+ ## Matchers for looking up custom resources
996
+
973
997
  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
998
 
975
999
  ```ruby
@@ -988,9 +1012,10 @@ it 'notifies the thing' do
988
1012
  end
989
1013
  ```
990
1014
 
1015
+ You can use this functionality to bundle lookup matchers with cookbooks, or to provide your own when the upstream cookbook doesn't include it.
1016
+
1017
+ ## Expecting Exceptions
991
1018
 
992
- Expecting Exceptions
993
- --------------------
994
1019
  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
1020
 
996
1021
  ```text
@@ -1041,8 +1066,8 @@ it 'raises an error' do
1041
1066
  end
1042
1067
  ```
1043
1068
 
1044
- Testing Multiple Recipes
1045
- -------------
1069
+ ## Testing Multiple Recipes
1070
+
1046
1071
  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
1072
 
1048
1073
  ```ruby
@@ -1066,8 +1091,8 @@ expect(chef_run).to install_package('lettuce')
1066
1091
  expect(chef_run).to install_package('tomato')
1067
1092
  ```
1068
1093
 
1069
- Testing Roles
1070
- -------------
1094
+ ## Testing Roles
1095
+
1071
1096
  Roles can also be used in a single `ChefSpec::SoloRunner` instance. Given a cookbook "bacon" with a default recipe:
1072
1097
 
1073
1098
  ```ruby
@@ -1126,9 +1151,8 @@ end
1126
1151
  ChefSpec::SoloRunner.new(role_path: '/var/my/roles') # local setting
1127
1152
  ```
1128
1153
 
1154
+ ## Faster Specs
1129
1155
 
1130
- Faster Specs
1131
- ------------
1132
1156
  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
1157
 
1134
1158
  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 +1167,8 @@ cached(:chef_run) { ChefSpec::SoloRunner.new }
1143
1167
 
1144
1168
  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
1169
 
1170
+ ## Media & Third-party Tutorials
1146
1171
 
1147
- Media & Third-party Tutorials
1148
- -----------------------------
1149
1172
  - [CustomInk's Testing Chef Cookbooks](http://technology.customink.com/blog/2012/08/03/testing-chef-cookbooks/)
1150
1173
  - [Jake Vanderdray's Practical ChefSpec](http://files.meetup.com/1780846/ChefSpec.pdf)
1151
1174
  - [Jim Hopp's excellent Test Driven Development for Chef Practitioners](http://www.youtube.com/watch?v=o2e0aZUAVGw)
@@ -1155,9 +1178,8 @@ Media & Third-party Tutorials
1155
1178
  - [Seth Vargo's TDDing tmux talk](http://www.confreaks.com/videos/2364-mwrc2013-tdding-tmux)
1156
1179
  - [Stephen Nelson Smith's Test-Driven Infrastructure with Chef](http://shop.oreilly.com/product/0636920030973.do)
1157
1180
 
1181
+ ## Development
1158
1182
 
1159
- Development
1160
- -----------
1161
1183
  1. Fork the repository from GitHub.
1162
1184
  2. Clone your fork to your local machine:
1163
1185
 
@@ -1172,16 +1194,19 @@ Development
1172
1194
  ```
1173
1195
 
1174
1196
  4. **Write tests**
1197
+
1175
1198
  5. Make your changes/patches/fixes, committing appropriately
1199
+
1176
1200
  6. Run the tests: `bundle exec rake`
1201
+
1177
1202
  7. Push your changes to GitHub
1203
+
1178
1204
  8. Open a Pull Request
1179
1205
 
1180
- ChefSpec is on [Travis CI](http://travis-ci.org/sethvargo/chefspec) which tests against multiple Chef and Ruby versions.
1206
+ ChefSpec is on [Travis CI][travis] which tests against multiple Chef and Ruby versions.
1181
1207
 
1182
1208
  If you are contributing, please see the [Contributing Guidelines](https://github.com/sethvargo/chefspec/blob/master/CONTRIBUTING.md) for more information.
1183
1209
 
1210
+ ## License
1184
1211
 
1185
- License
1186
- -------
1187
1212
  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
- # ChefSpec requires Ruby 2.1+ since ChefDK uses 2.1+ (depending on version)
27
- s.required_ruby_version = '>= 2.1'
26
+ s.required_ruby_version = '>= 2.2'
28
27
 
29
28
  s.add_dependency 'chef', '>= 12.0'
30
29
  s.add_dependency 'fauxhai', '~> 3.6'
31
30
  s.add_dependency 'rspec', '~> 3.0'
32
31
 
33
32
  # Development Dependencies
34
- s.add_development_dependency 'rake', '< 12.0'
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
 
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_package::install' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'installs a apt_package with the default action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_package::purge' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'purges a apt_package with an explicit action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_package::reconfig' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'reconfigs a apt_package with an explicit action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_package::remove' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'removes a apt_package with an explicit action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_package::upgrade' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'upgrades a apt_package with an explicit action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_repository::add' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'adds a apt_repository with default action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_repository::remove' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'removes a apt_repository with default action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_update::periodic' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'updates apt with default action' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'apt_update::update' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'updates apt repo' do
@@ -3,7 +3,7 @@ require 'chefspec'
3
3
  describe 'batch::run' do
4
4
  let(:chef_run) do
5
5
  ChefSpec::ServerRunner.new(platform: 'windows', version: '2012R2')
6
- .converge(described_recipe)
6
+ .converge(described_recipe)
7
7
  end
8
8
 
9
9
  it 'runs a batch with the default action' do