chefspec 5.3.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd963cf180a20e6c7271d54e58c941c719052754
4
- data.tar.gz: cc514dca888b1a8c99fcd4e4c917dc56df2ff8e5
3
+ metadata.gz: 211571e6c3653dfe0f5a14afc11aa7dc345ef5e2
4
+ data.tar.gz: e26799c5d30d08c00e23589efcff3ce68c64ca2f
5
5
  SHA512:
6
- metadata.gz: e3cc38869f14061cbe3b2ebaf3f6c46042429925b7495ef55b5471074f23a6afb435dd7aebfad101a4ffa943ef793fb28b176159a3bd5dd390365a3e7cd50e2c
7
- data.tar.gz: 1f5f5cf99b9926d07232b850d195d2817c58200d773ca419e16dd7fe64b9f3f81c93ad5fa931835e2430eb05787a8e4df94f0cc03ecc9fc39b9e4bbfeb58ea03
6
+ metadata.gz: 5837c6e05f8f156084ca693bcdbe6942817ccb6be32c6b93aa9f56ab1aca5e28db6a1dcc6abae66b89399362f38728d96e3fe13a5a111370ae8a1ebe5f249992
7
+ data.tar.gz: e7ba13ba29067d4f13c550bea471d7ff017416470f83247d6c131ca3868d1992315041eae4371121132f6d88d11b4fc086309d8280776bb7acc76b2b73d392d5
data/.travis.yml CHANGED
@@ -27,12 +27,6 @@ env:
27
27
  - CHEF_VERSION=12.8.1
28
28
  - CHEF_VERSION=12.7.2
29
29
  - 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
30
 
37
31
  matrix:
38
32
  fast_finish: true
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # CHANGELOG for ChefSpec
2
2
 
3
- ## 5.3.0 (October 20, 2016)
3
+ ## 5.4.0 (February 9, 2017)
4
+
5
+ IMPROVEMENTS
6
+
7
+ - Support for in-memory or on-disk ChefZero Servers. See README for usage details.
8
+
9
+ UPDATES
10
+
11
+ - While Chef 12.0 - 12.5 are still supported, they are no longer being tested.
12
+
13
+
14
+ ## 5.3.0 (October 29, 2016)
4
15
 
5
16
  IMPROVEMENTS
6
17
 
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
@@ -101,6 +92,9 @@ RSpec.configure do |config|
101
92
 
102
93
  # Specify the operating version to mock Ohai data from (default: nil)
103
94
  config.version = '14.04'
95
+
96
+ # When using ChefSpec::ServerRunner, specify the data storage method (options: in_memory, on_disk; default: in_memory)
97
+ config.server_runner_data_store = :on_disk
104
98
  end
105
99
  ```
106
100
 
@@ -129,6 +123,7 @@ ChefSpec::SoloRunner.new(log_level: :debug).converge(described_recipe)
129
123
  **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
124
 
131
125
  ### Berkshelf
126
+
132
127
  If you are using Berkshelf, simply require `chefspec/berkshelf` in your `spec_helper` after requiring `chefspec`:
133
128
 
134
129
  ```ruby
@@ -169,8 +164,7 @@ Requiring this file will:
169
164
  - Download all the dependencies listed in your `Cheffile` into the temporary directory
170
165
  - Set ChefSpec's `cookbook_path` to the temporary directory
171
166
 
172
- **NOTE** In order to test the cookbook in the current working directory, you
173
- have to write your `Cheffile` like this:
167
+ **NOTE** In order to test the cookbook in the current working directory, you have to write your `Cheffile` like this:
174
168
 
175
169
  ```ruby
176
170
  # Cheffile
@@ -180,6 +174,7 @@ cookbook 'name_of_your_cookbook', path: '.'
180
174
  ```
181
175
 
182
176
  ### Policyfile
177
+
183
178
  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
179
 
185
180
  ```ruby
@@ -203,8 +198,8 @@ default_source :community
203
198
  cookbook 'my-cookbook', path: '.'
204
199
  ```
205
200
 
206
- Running Specs
207
- -------------
201
+ ## Running Specs
202
+
208
203
  ChefSpec is actually an RSpec extension, so you can run your tests using the RSpec CLI:
209
204
 
210
205
  ```bash
@@ -219,9 +214,8 @@ $ rspec spec/unit/recipes/default_spec.rb --color
219
214
 
220
215
  For more information on the RSpec CLI, please see the [documentation](https://relishapp.com/rspec/rspec-core/docs/command-line).
221
216
 
217
+ ## Making Assertions
222
218
 
223
- Making Assertions
224
- -----------------
225
219
  ChefSpec asserts that resource actions have been performed. In general, ChefSpec follows the following pattern:
226
220
 
227
221
  ```ruby
@@ -280,7 +274,8 @@ ChefSpec includes matchers for all of Chef's core resources using the above sche
280
274
 
281
275
  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
276
 
283
- ##### include_recipe
277
+ ### include_recipe
278
+
284
279
  Assert that the Chef run included a recipe from another cookbook
285
280
 
286
281
  ```ruby
@@ -305,7 +300,8 @@ describe 'example::default' do
305
300
  end
306
301
  ```
307
302
 
308
- ##### notify
303
+ ### notify
304
+
309
305
  Assert that a resource notifies another in the Chef run
310
306
 
311
307
  ```ruby
@@ -313,7 +309,8 @@ resource = chef_run.template('/etc/foo')
313
309
  expect(resource).to notify('service[apache2]').to(:restart).immediately
314
310
  ```
315
311
 
316
- ##### subscribes
312
+ ### subscribes
313
+
317
314
  Assert that a resource subscribes to another in the Chef run
318
315
 
319
316
  ```ruby
@@ -321,7 +318,8 @@ resource = chef_run.service('apache2')
321
318
  expect(resource).to subscribe_to('template[/etc/foo]').on(:create).delayed
322
319
  ```
323
320
 
324
- ##### render_file
321
+ ### render_file
322
+
325
323
  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
324
 
327
325
  ```ruby
@@ -360,7 +358,8 @@ expect(chef_run).to install_package('apache2').at_converge_time
360
358
 
361
359
  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
360
 
363
- ##### do_nothing
361
+ ### do_nothing
362
+
364
363
  Assert that a resource performs no action
365
364
 
366
365
  ```ruby
@@ -370,9 +369,8 @@ expect(resource).to do_nothing
370
369
 
371
370
  **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
371
 
372
+ ## Setting node Attributes
373
373
 
374
- Setting node Attributes
375
- -----------------------
376
374
  Node attribute can be set when creating the `Runner`. The initializer yields a block that gives full access to the node object:
377
375
 
378
376
  ```ruby
@@ -386,6 +384,7 @@ end
386
384
  ```
387
385
 
388
386
  ### Automatic attributes
387
+
389
388
  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
389
 
391
390
  ```ruby
@@ -415,8 +414,8 @@ describe 'example::default' do
415
414
  end
416
415
  ```
417
416
 
418
- Using a Chef Server
419
- -------------------
417
+ ## Using a Chef Server
418
+
420
419
  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
420
 
422
421
  To use the ChefSpec server, simply replace `ChefSpec::SoloRunner` with `ChefSpec::ServerRunner`:
@@ -431,6 +430,7 @@ end
431
430
  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
431
 
433
432
  ### DSL
433
+
434
434
  The ChefSpec server includes a collection of helpful DSL methods for populating data into the Chef Server.
435
435
 
436
436
  Create a client:
@@ -511,10 +511,14 @@ end
511
511
 
512
512
  **NOTE** The ChefSpec server is empty at the start of each example to avoid interdependent tests.
513
513
 
514
+ ### Data Store
515
+
516
+ 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.
517
+
518
+ ## Stubbing
514
519
 
515
- Stubbing
516
- --------
517
520
  ### Command
521
+
518
522
  Given a recipe with shell guard:
519
523
 
520
524
  ```ruby
@@ -588,6 +592,7 @@ end
588
592
  ```
589
593
 
590
594
  Stub the output of the library helper. [Additional information](http://jtimberman.housepub.org/blog/2015/05/30/quick-tip-stubbing-library-helpers-in-chefspec/)
595
+
591
596
  ```ruby
592
597
  before do
593
598
  allow_any_instance_of(Chef::Node).to receive(:has_bacon?).and_return(true)
@@ -595,6 +600,7 @@ end
595
600
  ```
596
601
 
597
602
  ### Data Bag & Data Bag Item
603
+
598
604
  **NOTE** This is not required if you are using a ChefSpec server.
599
605
 
600
606
  Given a recipe that executes a `data_bag` method:
@@ -653,6 +659,7 @@ end
653
659
  ```
654
660
 
655
661
  ### Search
662
+
656
663
  **NOTE** This is not required if you are using a ChefSpec server.
657
664
 
658
665
  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 +696,8 @@ describe 'example::default' do
689
696
  end
690
697
  ```
691
698
 
699
+ ## Reporting
692
700
 
693
- Reporting
694
- ---------
695
701
  ChefSpec can generate a report of resources read over resources tested.
696
702
 
697
703
  To generate the coverage report, add the following to your `spec_helper.rb` before you require any "Chef" code:
@@ -754,7 +760,7 @@ For more complex scenarios, you can create a custom `Filter` object that inherit
754
760
 
755
761
  ```ruby
756
762
  class CustomFilter < ChefSpec::Coverage::Filter
757
- def initialize(arg1, arg2, &block)
763
+ def initialize(arg1, arg2, )
758
764
  # Create a custom initialization method, do some magic, etc.
759
765
  end
760
766
 
@@ -786,7 +792,8 @@ ChefSpec::Coverage.start! do
786
792
  set_template 'json.erb'
787
793
  end
788
794
  ```
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.
795
+
796
+ 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
797
 
791
798
  ```ruby
792
799
  ChefSpec::Coverage.start! do
@@ -794,9 +801,10 @@ ChefSpec::Coverage.start! do
794
801
  end
795
802
  ```
796
803
 
797
- Mocking Out Environments
798
- ------------------------
804
+ ## Mocking Out Environments
805
+
799
806
  ### ServerRunner
807
+
800
808
  ```ruby
801
809
  ChefSpec::ServerRunner.new do |node, server|
802
810
  # Create the environment
@@ -808,6 +816,7 @@ end
808
816
  ```
809
817
 
810
818
  ### SoloRunner
819
+
811
820
  If you want to mock out `node.chef_environment`, you'll need to use RSpec mocks/stubs twice:
812
821
 
813
822
  ```ruby
@@ -828,9 +837,8 @@ end
828
837
 
829
838
  **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
839
 
840
+ ## Testing LWRPs
831
841
 
832
- Testing LWRPs
833
- -------------
834
842
  **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
843
 
836
844
  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 +861,8 @@ end
853
861
 
854
862
  **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
863
 
864
+ ## Packaging Custom Matchers
856
865
 
857
- Packaging Custom Matchers
858
- -------------------------
859
866
  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
867
 
861
868
  ```ruby
@@ -876,13 +883,15 @@ end
876
883
  ```
877
884
 
878
885
  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.)
886
+
887
+ 1. The name of the resource to find in the resource collection (i.e. the name of the LWRP).
888
+ 2. The action that resource should receive.
889
+ 3. The value of the name attribute of the resource to find. (This is typically proxied as the value from the matcher definition.)
882
890
 
883
891
  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
892
 
885
- #### Example
893
+ ### Example
894
+
886
895
  Suppose I have a cookbook named "motd" with a resource/provider "message".
887
896
 
888
897
  ```ruby
@@ -950,9 +959,8 @@ end
950
959
 
951
960
  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
961
 
962
+ ## Writing Custom Matchers
953
963
 
954
- Writing Custom Matchers
955
- -----------------------
956
964
  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
965
 
958
966
  ```ruby
@@ -970,6 +978,8 @@ require_relative 'support/matchers'
970
978
 
971
979
  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
980
 
981
+ ## Matchers for looking up custom resources
982
+
973
983
  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
984
 
975
985
  ```ruby
@@ -988,9 +998,10 @@ it 'notifies the thing' do
988
998
  end
989
999
  ```
990
1000
 
1001
+ You can use this functionality to bundle lookup matchers with cookbooks, or to provide your own when the upstream cookbook doesn't include it.
1002
+
1003
+ ## Expecting Exceptions
991
1004
 
992
- Expecting Exceptions
993
- --------------------
994
1005
  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
1006
 
996
1007
  ```text
@@ -1041,8 +1052,8 @@ it 'raises an error' do
1041
1052
  end
1042
1053
  ```
1043
1054
 
1044
- Testing Multiple Recipes
1045
- -------------
1055
+ ## Testing Multiple Recipes
1056
+
1046
1057
  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
1058
 
1048
1059
  ```ruby
@@ -1066,8 +1077,8 @@ expect(chef_run).to install_package('lettuce')
1066
1077
  expect(chef_run).to install_package('tomato')
1067
1078
  ```
1068
1079
 
1069
- Testing Roles
1070
- -------------
1080
+ ## Testing Roles
1081
+
1071
1082
  Roles can also be used in a single `ChefSpec::SoloRunner` instance. Given a cookbook "bacon" with a default recipe:
1072
1083
 
1073
1084
  ```ruby
@@ -1126,9 +1137,8 @@ end
1126
1137
  ChefSpec::SoloRunner.new(role_path: '/var/my/roles') # local setting
1127
1138
  ```
1128
1139
 
1140
+ ## Faster Specs
1129
1141
 
1130
- Faster Specs
1131
- ------------
1132
1142
  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
1143
 
1134
1144
  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 +1153,8 @@ cached(:chef_run) { ChefSpec::SoloRunner.new }
1143
1153
 
1144
1154
  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
1155
 
1156
+ ## Media & Third-party Tutorials
1146
1157
 
1147
- Media & Third-party Tutorials
1148
- -----------------------------
1149
1158
  - [CustomInk's Testing Chef Cookbooks](http://technology.customink.com/blog/2012/08/03/testing-chef-cookbooks/)
1150
1159
  - [Jake Vanderdray's Practical ChefSpec](http://files.meetup.com/1780846/ChefSpec.pdf)
1151
1160
  - [Jim Hopp's excellent Test Driven Development for Chef Practitioners](http://www.youtube.com/watch?v=o2e0aZUAVGw)
@@ -1155,9 +1164,8 @@ Media & Third-party Tutorials
1155
1164
  - [Seth Vargo's TDDing tmux talk](http://www.confreaks.com/videos/2364-mwrc2013-tdding-tmux)
1156
1165
  - [Stephen Nelson Smith's Test-Driven Infrastructure with Chef](http://shop.oreilly.com/product/0636920030973.do)
1157
1166
 
1167
+ ## Development
1158
1168
 
1159
- Development
1160
- -----------
1161
1169
  1. Fork the repository from GitHub.
1162
1170
  2. Clone your fork to your local machine:
1163
1171
 
@@ -1172,16 +1180,19 @@ Development
1172
1180
  ```
1173
1181
 
1174
1182
  4. **Write tests**
1183
+
1175
1184
  5. Make your changes/patches/fixes, committing appropriately
1185
+
1176
1186
  6. Run the tests: `bundle exec rake`
1187
+
1177
1188
  7. Push your changes to GitHub
1189
+
1178
1190
  8. Open a Pull Request
1179
1191
 
1180
- ChefSpec is on [Travis CI](http://travis-ci.org/sethvargo/chefspec) which tests against multiple Chef and Ruby versions.
1192
+ ChefSpec is on [Travis CI][travis] which tests against multiple Chef and Ruby versions.
1181
1193
 
1182
1194
  If you are contributing, please see the [Contributing Guidelines](https://github.com/sethvargo/chefspec/blob/master/CONTRIBUTING.md) for more information.
1183
1195
 
1196
+ ## License
1184
1197
 
1185
- License
1186
- -------
1187
1198
  MIT - see the accompanying [LICENSE](https://github.com/sethvargo/chefspec/blob/master/LICENSE) file for details.
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
  @not_chef_12_7_2
9
3
  @not_chef_12_8_1
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
 
9
3
  Feature: The apt_update matcher
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
 
9
3
  Feature: The chocolatey_package matcher
@@ -1,6 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
-
4
1
  Feature: The dsc_resource matcher
5
2
  Background:
6
3
  * I am using the "dsc_resource" cookbook
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
  @not_chef_12_7_2
9
3
 
@@ -1,10 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
-
8
1
  Feature: The notifications matcher
9
2
  Background:
10
3
  * I am using the "notifications" cookbook
@@ -1,5 +1,3 @@
1
- @not_chef_12_0_3
2
-
3
1
  Feature: The openbsd_package matcher
4
2
  Background:
5
3
  * I am using the "openbsd_package" cookbook
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
 
9
3
  Feature: The osx_profile matcher
@@ -1,5 +1,3 @@
1
- @not_chef_12_0_3
2
-
3
1
  Feature: The paludis_package matcher
4
2
  Background:
5
3
  * I am using the "paludis_package" cookbook
@@ -1,10 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
-
8
1
  Feature: The script matcher
9
2
  Background:
10
3
  * I am using the "script" cookbook
@@ -0,0 +1,16 @@
1
+ Feature: The ChefSpec server with on-disk storage
2
+ Background:
3
+ * I am using the "server" cookbook
4
+
5
+ Scenario Outline: Running specs
6
+ * I successfully run `rspec spec/<Component>_spec.rb --require ../../../features/support/on_disk.rb`
7
+ * the output should contain "0 failures"
8
+ Examples:
9
+ | Component |
10
+ | client |
11
+ | data_bag |
12
+ | environment |
13
+ | node |
14
+ | render_with_cached |
15
+ | role |
16
+ | search |
@@ -1,10 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
-
8
1
  Feature: The subscribes matcher
9
2
  Background:
10
3
  * I am using the "subscribes" cookbook
@@ -0,0 +1,7 @@
1
+ # We need to add this setting because for the first test, we haven't had a chance
2
+ # to load the chefspec rspec.rb file, so the first test will fail if we simply
3
+ # try to set it like we would otherwise.
4
+
5
+ RSpec.configure do |config|
6
+ config.add_setting :server_runner_data_store, default: :on_disk
7
+ end
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
  @not_chef_12_7_2
9
3
  @not_chef_12_8_1
@@ -1,8 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
-
6
1
  Feature: The windows_package matcher
7
2
  Background:
8
3
  * I am using the "windows_package" cookbook
@@ -1,9 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
- @not_chef_12_4_3
6
- @not_chef_12_5_1
7
1
  @not_chef_12_6_0
8
2
  @not_chef_12_7_2
9
3
  @not_chef_12_8_1
@@ -1,8 +1,3 @@
1
- @not_chef_12_0_3
2
- @not_chef_12_1_2
3
- @not_chef_12_2_1
4
- @not_chef_12_3_0
5
-
6
1
  Feature: The zypper_package matcher
7
2
  Background:
8
3
  * I am using the "zypper_package" cookbook
@@ -1,11 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # travis runs on older chef releases failed while including
4
- # rack 2.X on Ruby 2.1. When we remove Ruby 2.1 support this can go
5
- if ENV['CHEF_VERSION'].to_f < 12.6
6
- gem 'rack', '~> 1.0'
7
- end
8
-
9
3
  if ENV['CHEF_VERSION'] == 'master'
10
4
  gem 'chef', github: 'chef/chef'
11
5
  else
@@ -19,4 +19,5 @@ RSpec.configure do |config|
19
19
  config.add_setting :path
20
20
  config.add_setting :platform
21
21
  config.add_setting :version
22
+ config.add_setting :server_runner_data_store, default: :in_memory
22
23
  end
@@ -16,6 +16,9 @@ module ChefSpec
16
16
 
17
17
  # Set a random port so ChefSpec may be run in multiple contexts
18
18
  port: port,
19
+
20
+ # Set the data store
21
+ data_store: data_store(RSpec.configuration.server_runner_data_store),
19
22
  )
20
23
  end
21
24
 
@@ -172,5 +175,27 @@ module ChefSpec
172
175
  @server.data_store.get(args)
173
176
  end
174
177
  end
178
+
179
+ #
180
+ # Generate the DataStore object to be passed in to the ChefZero::Server object
181
+ #
182
+ def data_store(option)
183
+ require "chef_zero/data_store/default_facade"
184
+
185
+ store = case option
186
+ when :in_memory
187
+ require "chef_zero/data_store/memory_store_v2"
188
+ ChefZero::DataStore::MemoryStoreV2.new
189
+ when :on_disk
190
+ require "tmpdir"
191
+ require "chef_zero/data_store/raw_file_store"
192
+ tmpdir = Dir.mktmpdir
193
+ ChefZero::DataStore::RawFileStore.new(Dir.mktmpdir)
194
+ else
195
+ raise ArgumentError, ":#{option} is not a valid server_runner_data_store option. Please use either :in_memory or :on_disk."
196
+ end
197
+
198
+ ChefZero::DataStore::DefaultFacade.new(store, "chef", true)
199
+ end
175
200
  end
176
201
  end
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '5.3.0'
2
+ VERSION = '5.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Crump
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-30 00:00:00.000000000 Z
12
+ date: 2017-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -736,6 +736,7 @@ files:
736
736
  - features/ruby_block.feature
737
737
  - features/script.feature
738
738
  - features/server.feature
739
+ - features/server_on_disk.feature
739
740
  - features/service.feature
740
741
  - features/smartos_package.feature
741
742
  - features/solaris_package.feature
@@ -751,6 +752,7 @@ files:
751
752
  - features/subversion.feature
752
753
  - features/support/env.rb
753
754
  - features/support/executor.rb
755
+ - features/support/on_disk.rb
754
756
  - features/systemd_unit.feature
755
757
  - features/template.feature
756
758
  - features/use_inline_resources.feature
@@ -940,7 +942,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
940
942
  version: '0'
941
943
  requirements: []
942
944
  rubyforge_project:
943
- rubygems_version: 2.6.7
945
+ rubygems_version: 2.6.10
944
946
  signing_key:
945
947
  specification_version: 4
946
948
  summary: Write RSpec examples and generate coverage reports for Chef recipes!
@@ -1009,6 +1011,7 @@ test_files:
1009
1011
  - features/ruby_block.feature
1010
1012
  - features/script.feature
1011
1013
  - features/server.feature
1014
+ - features/server_on_disk.feature
1012
1015
  - features/service.feature
1013
1016
  - features/smartos_package.feature
1014
1017
  - features/solaris_package.feature
@@ -1024,6 +1027,7 @@ test_files:
1024
1027
  - features/subversion.feature
1025
1028
  - features/support/env.rb
1026
1029
  - features/support/executor.rb
1030
+ - features/support/on_disk.rb
1027
1031
  - features/systemd_unit.feature
1028
1032
  - features/template.feature
1029
1033
  - features/use_inline_resources.feature