chefspec 3.4.0 → 4.0.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 -19
- data/CHANGELOG.md +32 -1
- data/CONTRIBUTING.md +1 -1
- data/README.md +37 -9
- data/chefspec.gemspec +2 -3
- data/examples/render_file/spec/default_spec.rb +32 -17
- data/examples/server/recipes/render_with_cached.rb +3 -0
- data/examples/server/spec/client_spec.rb +1 -1
- data/examples/server/spec/data_bag_spec.rb +1 -1
- data/examples/server/spec/environment_spec.rb +1 -1
- data/examples/server/spec/node_spec.rb +1 -1
- data/examples/server/spec/render_with_cached_spec.rb +16 -0
- data/examples/server/spec/role_spec.rb +1 -1
- data/features/server.feature +10 -12
- data/features/support/executor.rb +2 -0
- data/gemfiles/{chef-11.0.0.gemfile → chef-11.12.0.gemfile} +1 -1
- data/gemfiles/chef-master.gemfile +1 -1
- data/lib/chefspec.rb +1 -0
- data/lib/chefspec/api/erl_call.rb +5 -5
- data/lib/chefspec/api/execute.rb +5 -5
- data/lib/chefspec/api/powershell_script.rb +5 -5
- data/lib/chefspec/api/ruby_block.rb +2 -2
- data/lib/chefspec/api/script.rb +13 -2
- data/lib/chefspec/cacher.rb +2 -1
- data/lib/chefspec/coverage.rb +10 -2
- data/lib/chefspec/expect_exception.rb +0 -2
- data/lib/chefspec/extensions/chef/lwrp_base.rb +5 -1
- data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +19 -0
- data/lib/chefspec/librarian.rb +5 -2
- data/lib/chefspec/macros.rb +3 -3
- data/lib/chefspec/matchers/do_nothing_matcher.rb +4 -2
- data/lib/chefspec/matchers/include_recipe_matcher.rb +2 -2
- data/lib/chefspec/matchers/link_to_matcher.rb +11 -5
- data/lib/chefspec/matchers/notifications_matcher.rb +2 -2
- data/lib/chefspec/matchers/render_file_matcher.rb +9 -3
- data/lib/chefspec/matchers/resource_matcher.rb +2 -2
- data/lib/chefspec/matchers/state_attrs_matcher.rb +2 -2
- data/lib/chefspec/matchers/subscribes_matcher.rb +4 -4
- data/lib/chefspec/renderer.rb +1 -1
- data/lib/chefspec/rspec.rb +1 -0
- data/lib/chefspec/runner.rb +2 -1
- data/lib/chefspec/server.rb +90 -19
- data/lib/chefspec/version.rb +1 -1
- data/spec/unit/cacher_spec.rb +1 -1
- data/spec/unit/expect_exception_spec.rb +6 -6
- data/spec/unit/extensions/lwrp_base_spec.rb +9 -1
- data/spec/unit/macros_spec.rb +6 -6
- data/spec/unit/matchers/include_recipe_matcher_spec.rb +6 -6
- data/spec/unit/matchers/link_to_matcher_spec.rb +31 -15
- data/spec/unit/matchers/notifications_matcher_spec.rb +4 -4
- data/spec/unit/matchers/render_file_matcher_spec.rb +19 -10
- data/spec/unit/matchers/state_attrs_matcher_spec.rb +28 -24
- data/spec/unit/matchers/subscribes_matcher_spec.rb +7 -7
- data/spec/unit/renderer_spec.rb +7 -7
- data/spec/unit/runner_spec.rb +39 -9
- metadata +10 -25
- data/gemfiles/chef-11.2.0.gemfile +0 -5
- data/gemfiles/chef-11.4.4.gemfile +0 -5
- data/gemfiles/chef-11.6.0.gemfile +0 -5
- data/gemfiles/chef-11.8.0.gemfile +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd833d7dcb6a3d973ccd35a43a0f606142244b8f
|
4
|
+
data.tar.gz: c2c2d2832263d9868c542d7cc005b4f626bfe863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02158758eeff60f14350d2084279b07046c1534e04f20f7392700471b79bd44316ddd57af76a21420e613ca7c115c33870fbcec3de4ea027e20a8575bef1e529
|
7
|
+
data.tar.gz: 62660485d2405c57a6e17a1b566f7a344ef86fad27fba8520a5aea451a304bd5429d5a72aab869c37c4c7cebd869b8e8f16a6311cdce9466826ee7b04ff03691
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
rvm:
|
2
2
|
- 1.9.3
|
3
3
|
- 2.0.0
|
4
|
-
- 2.1
|
4
|
+
- 2.1
|
5
5
|
|
6
6
|
branches:
|
7
7
|
only:
|
@@ -19,27 +19,10 @@ notifications:
|
|
19
19
|
bundler_args: --jobs 7
|
20
20
|
|
21
21
|
gemfile:
|
22
|
-
- gemfiles/chef-11.
|
23
|
-
- gemfiles/chef-11.2.0.gemfile
|
24
|
-
- gemfiles/chef-11.4.4.gemfile
|
25
|
-
- gemfiles/chef-11.6.0.gemfile
|
26
|
-
- gemfiles/chef-11.8.0.gemfile
|
22
|
+
- gemfiles/chef-11.12.0.gemfile
|
27
23
|
- gemfiles/chef-master.gemfile
|
28
24
|
|
29
25
|
matrix:
|
30
26
|
fast_finish: true
|
31
27
|
allow_failures:
|
32
28
|
- gemfile: gemfiles/chef-master.gemfile
|
33
|
-
exclude:
|
34
|
-
- rvm: 2.0.0
|
35
|
-
gemfile: gemfiles/chef-11.0.0.gemfile
|
36
|
-
- rvm: 2.0.0
|
37
|
-
gemfile: gemfiles/chef-11.2.0.gemfile
|
38
|
-
- rvm: 2.0.0
|
39
|
-
gemfile: gemfiles/chef-11.4.4.gemfile
|
40
|
-
- rvm: 2.1.0
|
41
|
-
gemfile: gemfiles/chef-11.0.0.gemfile
|
42
|
-
- rvm: 2.1.0
|
43
|
-
gemfile: gemfiles/chef-11.2.0.gemfile
|
44
|
-
- rvm: 2.1.0
|
45
|
-
gemfile: gemfiles/chef-11.4.4.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,38 @@
|
|
1
1
|
CHANGELOG for ChefSpec
|
2
2
|
======================
|
3
3
|
|
4
|
-
##
|
4
|
+
## 4.0.0 (June 2, 2014)
|
5
|
+
Breaking Changes:
|
6
|
+
- **Upgraded to RSpec 3!** RSpec 3 brings many new API changes and syntaxes
|
7
|
+
- **Bump minimum required Chef version to 11.12!** Without this change, Chef Zero will blow up
|
8
|
+
|
9
|
+
Bugfixes:
|
10
|
+
- Gracefully fail if a resource does not report it's source line in the reporter
|
11
|
+
- Pull the correct cookbook folder from the stack on Windows (88bfc6)
|
12
|
+
- Cover resources in render_file matchers for reporting
|
13
|
+
- Cover resources in link_to matchers for reporting
|
14
|
+
- Cover resources in do_nothing matchers for reporting
|
15
|
+
- Fix memory leak in LWRP Resource classes
|
16
|
+
- Restore the original `cookbook_path` when using librarian-chef
|
17
|
+
- Documentation fixes
|
18
|
+
- Disable lazy loading of cached resources
|
19
|
+
- Fix a bug that will happen in later Chef versions because FreeBSD is evil (13ff143)
|
20
|
+
- Do not pass local file paths to `preferred_filename_on_disk_location`
|
21
|
+
|
22
|
+
Features:
|
23
|
+
- Add runner methods for all the bash, csh, perl, etc resources
|
24
|
+
- Upgraded fauxhai dependency and specs
|
25
|
+
- Upgrade Chef Zero for multi-org support
|
26
|
+
|
27
|
+
Improvements:
|
28
|
+
- Improved documentation around the `define_runner_method` method
|
29
|
+
- Update badges to be all SVG
|
30
|
+
- Test on Ruby 2.1
|
31
|
+
- Use a randomly assigned port for Chef Zero
|
32
|
+
- Remove references to `.stub` from documentation
|
33
|
+
|
34
|
+
|
35
|
+
## 3.4.0 (March 16, 2014)
|
5
36
|
Bugfixes:
|
6
37
|
- Restore Berkshelf 2 support (missing edge case)
|
7
38
|
- Add negative failure message for subscribes/notifies matchers
|
data/CONTRIBUTING.md
CHANGED
@@ -19,7 +19,7 @@ Will Not Merge
|
|
19
19
|
--------------
|
20
20
|
This section details, specifically, Pull Requests or features that will _not_ be merged:
|
21
21
|
|
22
|
-
1. Matchers for non-Chef core resources. ChefSpec 3.0 introduced a way for cookbook maintainers to [package matchers _with_ their cookbooks](https://github.com/sethvargo/chefspec
|
22
|
+
1. Matchers for non-Chef core resources. ChefSpec 3.0 introduced a way for cookbook maintainers to [package matchers _with_ their cookbooks](https://github.com/sethvargo/chefspec#packaging-custom-matchers) at distribution time.
|
23
23
|
2. New features without accompanying unit tests, cucumber tests, and documentation.
|
24
24
|
|
25
25
|
|
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
ChefSpec
|
2
2
|
========
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![Dependency Status](
|
6
|
-
[![Code Climate](
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/chefspec.svg)][gem]
|
4
|
+
[![Build Status](http://img.shields.io/travis/sethvargo/chefspec.svg)][travis]
|
5
|
+
[![Dependency Status](http://img.shields.io/gemnasium/sethvargo/chefspec.svg)][gemnasium]
|
6
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/sethvargo/chefspec.svg)][codeclimate]
|
7
|
+
[![Gittip](http://img.shields.io/gittip/sethvargo.svg)][gittip]
|
8
|
+
|
9
|
+
[gem]: https://rubygems.org/gems/chefspec
|
10
|
+
[travis]: http://travis-ci.org/sethvargo/chefspec
|
11
|
+
[gemnasium]: https://gemnasium.com/sethvargo/chefspec
|
12
|
+
[codeclimate]: https://codeclimate.com/github/sethvargo/chefspec
|
13
|
+
[gittip]: https://www.gittip.com/sethvargo
|
7
14
|
|
8
15
|
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.
|
9
16
|
|
@@ -83,6 +90,9 @@ RSpec.configure do |config|
|
|
83
90
|
# the location of the calling spec file])
|
84
91
|
config.cookbook_path = '/var/cookbooks'
|
85
92
|
|
93
|
+
# Set the organization for Chef Zero (default: 'chefspec')
|
94
|
+
config.organization = 'sweetsauce'
|
95
|
+
|
86
96
|
# Specify the path for Chef Solo to find roles (default: [ascending search])
|
87
97
|
config.role_path = '/var/roles'
|
88
98
|
|
@@ -520,7 +530,7 @@ If you are using **Encrypted Data Bag Items**, you'll need to dive into the RSpe
|
|
520
530
|
```ruby
|
521
531
|
describe 'example::default' do
|
522
532
|
before do
|
523
|
-
Chef::EncryptedDataBagItem.
|
533
|
+
allow(Chef::EncryptedDataBagItem).to receive(:load).with('users', 'svargo').and_return(...)
|
524
534
|
end
|
525
535
|
end
|
526
536
|
```
|
@@ -636,7 +646,7 @@ class CustomFilter < ChefSpec::Coverage::Filter
|
|
636
646
|
end
|
637
647
|
end
|
638
648
|
|
639
|
-
ChefSpec::
|
649
|
+
ChefSpec::Coverage.start! do
|
640
650
|
add_filter CustomFilter.new('foo', :bar)
|
641
651
|
end
|
642
652
|
```
|
@@ -664,10 +674,10 @@ let(:chef_run) do
|
|
664
674
|
env.name 'staging'
|
665
675
|
|
666
676
|
# Stub the node to return this environment
|
667
|
-
node.
|
677
|
+
allow(node).to receive(:chef_environment).and_return(env.name)
|
668
678
|
|
669
679
|
# Stub any calls to Environment.load to return this environment
|
670
|
-
Chef::Environment.
|
680
|
+
allow(Chef::Environment).to receive(:load).and_return(env)
|
671
681
|
end.converge('cookbook::recipe')
|
672
682
|
end
|
673
683
|
```
|
@@ -788,6 +798,24 @@ require_relative 'support/matchers'
|
|
788
798
|
|
789
799
|
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).
|
790
800
|
|
801
|
+
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.
|
802
|
+
|
803
|
+
```ruby
|
804
|
+
# matchers.rb
|
805
|
+
ChefSpec::Runner.define_runner_method :my_custom_resource
|
806
|
+
```
|
807
|
+
|
808
|
+
And then in your spec suite, you can obtain the custom resource for assertions:
|
809
|
+
|
810
|
+
```ruby
|
811
|
+
let(:chef_run) { ChefSpec::Runner.new('...') }
|
812
|
+
|
813
|
+
it 'notifies the thing' do
|
814
|
+
custom = chef_run.my_custom_resource('name')
|
815
|
+
expect(custom).to notify('service[apache2]').to(:restart).immediately
|
816
|
+
end
|
817
|
+
```
|
818
|
+
|
791
819
|
|
792
820
|
Expecting Exceptions
|
793
821
|
--------------------
|
@@ -917,7 +945,7 @@ Next, convert all your `let` blocks to `cached`:
|
|
917
945
|
|
918
946
|
```ruby
|
919
947
|
# before
|
920
|
-
let(:chef_run) { ChefSpec::
|
948
|
+
let(:chef_run) { ChefSpec::Runner.new }
|
921
949
|
|
922
950
|
# after
|
923
951
|
cached(:chef_run) { ChefSpec::Runner.new }
|
data/chefspec.gemspec
CHANGED
@@ -26,12 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
# ChefSpec requires Ruby 1.9+
|
27
27
|
s.required_ruby_version = '>= 1.9'
|
28
28
|
|
29
|
-
s.add_dependency 'chef', '~> 11.
|
29
|
+
s.add_dependency 'chef', '~> 11.12'
|
30
30
|
s.add_dependency 'fauxhai', '~> 2.0'
|
31
|
-
s.add_dependency 'rspec', '~>
|
31
|
+
s.add_dependency 'rspec', '~> 3.0'
|
32
32
|
|
33
33
|
# Development Dependencies
|
34
|
-
s.add_development_dependency 'chef-zero', '~> 1.7'
|
35
34
|
s.add_development_dependency 'rake'
|
36
35
|
s.add_development_dependency 'redcarpet', '~> 3.0'
|
37
36
|
s.add_development_dependency 'yard', '~> 0.8'
|
@@ -30,28 +30,43 @@ describe 'render_file::default' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'cookbook_file' do
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
shared_examples 'renders file' do
|
34
|
+
it 'renders the file' do
|
35
|
+
expect(chef_run).to render_file('/tmp/cookbook_file')
|
36
|
+
expect(chef_run).to_not render_file('/tmp/not_cookbook_file')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'renders the file with content' do
|
40
|
+
expect(chef_run).to render_file('/tmp/cookbook_file').with_content('This is content!')
|
41
|
+
expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content('This is not content!')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'renders the file with matching content' do
|
45
|
+
expect(chef_run).to render_file('/tmp/cookbook_file').with_content(/^This(.+)$/)
|
46
|
+
expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content(/^Not(.+)$/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'renders the file with content matching arbitrary matcher' do
|
50
|
+
expect(chef_run).to render_file('/tmp/cookbook_file').with_content(
|
51
|
+
start_with('This')
|
52
|
+
)
|
53
|
+
expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content(
|
54
|
+
end_with('not')
|
55
|
+
)
|
56
|
+
end
|
36
57
|
end
|
37
58
|
|
38
|
-
|
39
|
-
|
40
|
-
expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content('This is not content!')
|
59
|
+
context 'with a pristine filesystem' do
|
60
|
+
it_behaves_like 'renders file'
|
41
61
|
end
|
42
62
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
63
|
+
context 'with a same rendered file on filesystem' do
|
64
|
+
before do
|
65
|
+
allow(File).to receive(:read).and_call_original
|
66
|
+
allow(File).to receive(:read).with('/tmp/cookbook_file', 'rb').and_yield('This is content!')
|
67
|
+
end
|
47
68
|
|
48
|
-
|
49
|
-
expect(chef_run).to render_file('/tmp/cookbook_file').with_content(
|
50
|
-
start_with('This')
|
51
|
-
)
|
52
|
-
expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content(
|
53
|
-
end_with('not')
|
54
|
-
)
|
69
|
+
it_behaves_like 'renders file'
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require 'chefspec/cacher'
|
3
|
+
require 'chefspec/server'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.extend(ChefSpec::Cacher)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'server::render_with_cached' do
|
10
|
+
cached(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
11
|
+
|
12
|
+
it 'does not cache file requests' do
|
13
|
+
expect(chef_run).to render_file('/tmp/file')
|
14
|
+
expect(chef_run).to render_file('/tmp/file').with_content('This is content!')
|
15
|
+
end
|
16
|
+
end
|
data/features/server.feature
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# that doesn't work with Chef Chef 11.0.0 and 11.2.0.
|
1
|
+
# Need to spawn a sub-process; otherwise future tests will fail because the
|
2
|
+
# server is running
|
4
3
|
@spawn
|
5
|
-
@not_chef_11_0_0
|
6
|
-
@not_chef_11_2_0
|
7
4
|
Feature: The ChefSpec server
|
8
5
|
Background:
|
9
6
|
* I am using the "server" cookbook
|
@@ -12,10 +9,11 @@ Feature: The ChefSpec server
|
|
12
9
|
* I successfully run `rspec spec/<Compontent>_spec.rb`
|
13
10
|
* the output should contain "0 failures"
|
14
11
|
Examples:
|
15
|
-
| Compontent
|
16
|
-
| client
|
17
|
-
| data_bag
|
18
|
-
| environment
|
19
|
-
| node
|
20
|
-
|
|
21
|
-
|
|
12
|
+
| Compontent |
|
13
|
+
| client |
|
14
|
+
| data_bag |
|
15
|
+
| environment |
|
16
|
+
| node |
|
17
|
+
| render_with_cached |
|
18
|
+
| role |
|
19
|
+
| search |
|
data/lib/chefspec.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative 'chefspec/extensions/chef/data_query'
|
|
6
6
|
require_relative 'chefspec/extensions/chef/lwrp_base'
|
7
7
|
require_relative 'chefspec/extensions/chef/resource'
|
8
8
|
require_relative 'chefspec/extensions/chef/securable'
|
9
|
+
require_relative 'chefspec/extensions/chef/resource/freebsd_package'
|
9
10
|
|
10
11
|
require_relative 'chefspec/mixins/normalize'
|
11
12
|
|
@@ -15,19 +15,19 @@ module ChefSpec::API
|
|
15
15
|
# The Examples section demonstrates the different ways to test an
|
16
16
|
# +erl_call+ resource with ChefSpec.
|
17
17
|
#
|
18
|
-
# @example Assert that an +erl_call+ was
|
18
|
+
# @example Assert that an +erl_call+ was run
|
19
19
|
# expect(chef_run).to run_erl_call('net_adm:names()')
|
20
20
|
#
|
21
|
-
# @example Assert that an +erl_call+ was
|
21
|
+
# @example Assert that an +erl_call+ was run with predicate matchers
|
22
22
|
# expect(chef_run).to run_erl_call('net_adm:names()').with_node_name('example')
|
23
23
|
#
|
24
|
-
# @example Assert that an +erl_call+ was
|
24
|
+
# @example Assert that an +erl_call+ was run with attributes
|
25
25
|
# expect(chef_run).to run_erl_call('net_adm:names()').with(node_name: 'example')
|
26
26
|
#
|
27
|
-
# @example Assert that an +erl_call+ was
|
27
|
+
# @example Assert that an +erl_call+ was run using a regex
|
28
28
|
# expect(chef_run).to run_erl_call('net_adm:names()').with(node_name: /[a-z]+/)
|
29
29
|
#
|
30
|
-
# @example Assert that an +erl_call+ was _not_
|
30
|
+
# @example Assert that an +erl_call+ was _not_ run
|
31
31
|
# expect(chef_run).to_not run_erl_call('net_adm:names()')
|
32
32
|
#
|
33
33
|
#
|
data/lib/chefspec/api/execute.rb
CHANGED
@@ -15,19 +15,19 @@ module ChefSpec::API
|
|
15
15
|
# The Examples section demonstrates the different ways to test an
|
16
16
|
# +execute+ resource with ChefSpec.
|
17
17
|
#
|
18
|
-
# @example Assert that an +execute+ was
|
18
|
+
# @example Assert that an +execute+ was run
|
19
19
|
# expect(chef_run).to run_execute('echo "hello"')
|
20
20
|
#
|
21
|
-
# @example Assert that an +execute+ was
|
21
|
+
# @example Assert that an +execute+ was run with predicate matchers
|
22
22
|
# expect(chef_run).to run_execute('echo "hello"').with_user('svargo')
|
23
23
|
#
|
24
|
-
# @example Assert that an +execute+ was
|
24
|
+
# @example Assert that an +execute+ was run with attributes
|
25
25
|
# expect(chef_run).to run_execute('echo "hello"').with(user: 'svargo')
|
26
26
|
#
|
27
|
-
# @example Assert that an +execute+ was
|
27
|
+
# @example Assert that an +execute+ was run using a regex
|
28
28
|
# expect(chef_run).to run_execute('echo "hello"').with(user: /sva(.+)/)
|
29
29
|
#
|
30
|
-
# @example Assert that an +execute+ was _not_
|
30
|
+
# @example Assert that an +execute+ was _not_ run
|
31
31
|
# expect(chef_run).to_not run_execute('echo "hello"')
|
32
32
|
#
|
33
33
|
#
|