chefspec 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +18 -0
- data/examples/stub_search/recipes/block.rb +3 -0
- data/examples/stub_search/recipes/default.rb +2 -5
- data/examples/stub_search/spec/block_spec.rb +27 -0
- data/features/stub_search.feature +1 -1
- data/lib/chefspec/coverage.rb +25 -7
- data/lib/chefspec/extensions/chef/data_query.rb +6 -1
- data/lib/chefspec/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11a70e63e41d70878f57327c5ed4008b49901a78
|
4
|
+
data.tar.gz: 7cfbd1b0ed9431a5c0ecba7d2445679863d61afd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28874630542168cc116ab2a951a0254dc3eb7c23406c7dcffaf920a903948c09a32604d7c695254ee0065fc2ce3c345802cab5e78bb508206098069c490ab39d
|
7
|
+
data.tar.gz: 82d8a732f2d4a24b2c6350a0455a8d2bff1205d27f86ad65fed549f861460bf679152b650f6b50d5078eea42c3e40dc7b1d249193e9d6a9734d92f87cbbecc30
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# CHANGELOG for ChefSpec
|
2
2
|
|
3
|
+
## 6.2.0 (March 27, 2017)
|
4
|
+
|
5
|
+
- Correctly handle the block form of search() when using stubs
|
6
|
+
- Add support for alternative reporting output from Coverage.report!
|
7
|
+
|
3
8
|
## 6.1.0 (March 9, 2017)
|
4
9
|
|
5
10
|
- Loosen the Fauxhai dependency to allow Fauxhai 4.0 This deprecates a large number of Ohai mocks for end of life platforms. See <https://github.com/customink/fauxhai/blob/master/PLATFORMS.md> for the current list of platforms supported by Fauxhai
|
data/README.md
CHANGED
@@ -815,6 +815,24 @@ ChefSpec::Coverage.start! do
|
|
815
815
|
end
|
816
816
|
```
|
817
817
|
|
818
|
+
If you would like to add alternative reporting for the Coverage.report! ouput, you can supply your own by calling add_output in the `ChefSepc::Coverage` block:
|
819
|
+
Note the reportOutput has the following items in it: total, touched, coverage and collections of untouched_resources and all_resources
|
820
|
+
|
821
|
+
```ruby
|
822
|
+
ChefSpec::Coverage.start! do
|
823
|
+
add_output do |reportOutput|
|
824
|
+
File.open( "coverage.json","w" ) do |f|
|
825
|
+
f.puts(reportOutput[:total])
|
826
|
+
f.puts(reportOutput[:touched])
|
827
|
+
f.puts(reportOutput[:coverage])
|
828
|
+
f.puts(reportOutput[:untouched_resources])
|
829
|
+
f.puts(reportOutput[:all_resources])
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
```
|
834
|
+
Note the above example outputs the raw data without applying formatting.
|
835
|
+
|
818
836
|
## Mocking Out Environments
|
819
837
|
|
820
838
|
### ServerRunner
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
|
3
|
+
describe 'stub_search::block' do
|
4
|
+
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }
|
5
|
+
|
6
|
+
context 'when the search is not stubbed' do
|
7
|
+
it 'raises an exception' do
|
8
|
+
expect do
|
9
|
+
chef_run
|
10
|
+
end.to raise_error(ChefSpec::Error::SearchNotStubbed)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'as a String' do
|
15
|
+
it 'does not raise an exception' do
|
16
|
+
stub_search(:node, 'roles:web').and_return([{ name: 'example.com' }])
|
17
|
+
expect { chef_run }.to_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'as a Regexp' do
|
22
|
+
it 'does not raise an exception' do
|
23
|
+
stub_search(:node, /roles:(.+)/).and_return([{ name: 'example.com' }])
|
24
|
+
expect { chef_run }.to_not raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/chefspec/coverage.rb
CHANGED
@@ -28,6 +28,15 @@ module ChefSpec
|
|
28
28
|
def initialize
|
29
29
|
@collection = {}
|
30
30
|
@filters = {}
|
31
|
+
@outputs = []
|
32
|
+
add_output do |report|
|
33
|
+
begin
|
34
|
+
erb = Erubis::Eruby.new(File.read(@template))
|
35
|
+
puts erb.evaluate(report)
|
36
|
+
rescue NameError => e
|
37
|
+
raise Error::ErbTemplateParseError.new(original_error: e.message)
|
38
|
+
end
|
39
|
+
end
|
31
40
|
@template = ChefSpec.root.join('templates', 'coverage', 'human.erb')
|
32
41
|
end
|
33
42
|
|
@@ -41,7 +50,7 @@ module ChefSpec
|
|
41
50
|
end
|
42
51
|
|
43
52
|
#
|
44
|
-
# Add a filter to the
|
53
|
+
# Add a filter to the coverage analysis.
|
45
54
|
#
|
46
55
|
# @param [Filter, String, Regexp] filter
|
47
56
|
# the filter to add
|
@@ -68,6 +77,18 @@ module ChefSpec
|
|
68
77
|
|
69
78
|
true
|
70
79
|
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Add an output to send the coverage results to.
|
83
|
+
# @param [Proc] block
|
84
|
+
# the block to use as the output
|
85
|
+
#
|
86
|
+
# @return [true]
|
87
|
+
#
|
88
|
+
def add_output(&block)
|
89
|
+
@outputs << block
|
90
|
+
end
|
91
|
+
|
71
92
|
#
|
72
93
|
# Change the template for reporting of converage analysis.
|
73
94
|
#
|
@@ -151,12 +172,9 @@ module ChefSpec
|
|
151
172
|
resource unless resource.touched?
|
152
173
|
end.compact
|
153
174
|
report[:all_resources] = @collection.values
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
puts erb.evaluate(report)
|
158
|
-
rescue NameError => e
|
159
|
-
raise Error::ErbTemplateParseError.new(original_error: e.message)
|
175
|
+
|
176
|
+
@outputs.each do |block|
|
177
|
+
self.instance_exec(report, &block)
|
160
178
|
end
|
161
179
|
|
162
180
|
# Ensure we exit correctly (#351)
|
@@ -14,7 +14,12 @@ module Chef::DSL::DataQuery
|
|
14
14
|
raise ChefSpec::Error::SearchNotStubbed.new(args: [type, query])
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
if block
|
18
|
+
Array(stub.result).each {|r| block.call(r) }
|
19
|
+
true
|
20
|
+
else
|
21
|
+
stub.result
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
# @see Chef::DSL::DataQuery#data_bag
|
data/lib/chefspec/version.rb
CHANGED
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: 6.
|
4
|
+
version: 6.2.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: 2017-03-
|
12
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -582,7 +582,9 @@ files:
|
|
582
582
|
- examples/stub_data_bag_item/spec/default_spec.rb
|
583
583
|
- examples/stub_node/recipes/default.rb
|
584
584
|
- examples/stub_node/spec/default_spec.rb
|
585
|
+
- examples/stub_search/recipes/block.rb
|
585
586
|
- examples/stub_search/recipes/default.rb
|
587
|
+
- examples/stub_search/spec/block_spec.rb
|
586
588
|
- examples/stub_search/spec/default_spec.rb
|
587
589
|
- examples/subscribes/recipes/before.rb
|
588
590
|
- examples/subscribes/recipes/chained.rb
|
@@ -973,7 +975,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
973
975
|
version: '0'
|
974
976
|
requirements: []
|
975
977
|
rubyforge_project:
|
976
|
-
rubygems_version: 2.6.
|
978
|
+
rubygems_version: 2.6.11
|
977
979
|
signing_key:
|
978
980
|
specification_version: 4
|
979
981
|
summary: Write RSpec examples and generate coverage reports for Chef recipes!
|