chefspec 6.1.0 → 6.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea0e7c6ed02f2b96fb4c08e4dd4e06af0c78ddc8
4
- data.tar.gz: 153afc4930a9ce02084b4196caf01f73d8072a93
3
+ metadata.gz: 11a70e63e41d70878f57327c5ed4008b49901a78
4
+ data.tar.gz: 7cfbd1b0ed9431a5c0ecba7d2445679863d61afd
5
5
  SHA512:
6
- metadata.gz: 0b672dcfb994f0e56022f024dac08344574ac51bb4b454ec34b373c95dd4e30248970bb8fc709e74c5a48534708303aebfc667f890dd7e1fd8d25ab328346959
7
- data.tar.gz: '09db04b5da70480e38fc39886bc53782cca60a2fa24c604265e8d1dccb36b41a8eb4ac5271f0663502e3eb07810cc4fee1995e084edf9bf19f10a1a36328f4e7'
6
+ metadata.gz: 28874630542168cc116ab2a951a0254dc3eb7c23406c7dcffaf920a903948c09a32604d7c695254ee0065fc2ce3c345802cab5e78bb508206098069c490ab39d
7
+ data.tar.gz: 82d8a732f2d4a24b2c6350a0455a8d2bff1205d27f86ad65fed549f861460bf679152b650f6b50d5078eea42c3e40dc7b1d249193e9d6a9734d92f87cbbecc30
@@ -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,3 @@
1
+ hosts = []
2
+ search(:node, 'roles:web') {|n| hosts << n['name'] }
3
+ raise 'test failure' unless hosts.length == 1 && hosts[0] == 'example.com'
@@ -1,5 +1,2 @@
1
- template '/tmp/specific_stub' do
2
- variables(
3
- nodes: search(:node, 'name:example.com')
4
- )
5
- end
1
+ hosts = search(:node, 'name:example.com')
2
+ raise 'test failure' unless hosts.length == 1 && hosts[0]['name'] == 'example.com'
@@ -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
@@ -3,5 +3,5 @@ Feature: The stub_search matcher
3
3
  * I am using the "stub_search" cookbook
4
4
 
5
5
  Scenario: Running specs
6
- * I successfully run `rspec spec/default_spec.rb`
6
+ * I successfully run `rspec spec/default_spec.rb spec/block_spec.rb`
7
7
  * the output should contain "0 failures"
@@ -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 converage analysis.
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
- begin
156
- erb = Erubis::Eruby.new(File.read(@template))
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
- stub.result
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
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '6.1.0'
2
+ VERSION = '6.2.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: 6.1.0
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-10 00:00:00.000000000 Z
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.10
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!