rspec-puppet 2.6.13 → 2.6.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,23 @@
2
2
  All notable changes to this project will be documented in this file. This
3
3
  project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [2.6.14]
6
+
7
+ ### Fixed
8
+
9
+ * If present, `Win32::Dir` will be used to managed the fixtures directory
10
+ junction on Windows as the builtin `File` module does not have complete
11
+ support for directory junctions on Ruby <= 2.1.
12
+
13
+ ### Changed
14
+
15
+ * Resource coverage results are now exposed to the configured RSpec reporter
16
+ rather than only being printed to STDOUT.
17
+ * If running with parallel\_tests, resource coverage data is stored in
18
+ per-process temp files and merged at the end of the final rspec process,
19
+ allowing for a complete coverage report to be generated when splitting
20
+ a test suite across multiple rspec processes.
21
+
5
22
  ## [2.6.13]
6
23
 
7
24
  ### Fixed
data/README.md CHANGED
@@ -1055,8 +1055,9 @@ be excluded from the coverage report.
1055
1055
  * [puppetlabs_spec_helper](https://github.com/puppetlabs/puppetlabs_spec_helper): shared spec helpers to setup puppet
1056
1056
  * [rspec-puppet-augeas](https://github.com/domcleal/rspec-puppet-augeas): RSpec tests for Augeas resources inside Puppet manifests
1057
1057
  * [jimdo-rspec-puppet-helpers](https://github.com/Jimdo/jimdo-rspec-puppet-helpers): Tests the contents of a file with a source
1058
- * [puppet-catalog_rspec](https://github.com/enterprisemodules/puppet-catalog_rspec): Ease development of specs by dumping the Puppet catalog as RSpec code
1059
-
1058
+ * Ease development of specs
1059
+ * [puppet-catalog_rspec](https://github.com/enterprisemodules/puppet-catalog_rspec): Dump the Puppet Catalog as RSpec code at compile time
1060
+ * [create_specs](https://github.com/alexharv074/create_specs.git): A different implementation that takes a compiled catalog and writes out RSpec code with various options
1060
1061
  * Fact providers
1061
1062
  * [rspec-puppet-facts](https://github.com/mcanevet/rspec-puppet-facts): Simplify your unit tests by looping on every supported Operating System and populating facts.
1062
1063
  * [rspec-puppet-osmash](https://github.com/Aethylred/rspec-puppet-osmash): Provides Operation System hashes and validations for rspec-puppet
@@ -1,3 +1,8 @@
1
+ require 'tmpdir'
2
+ require 'digest'
3
+ require 'json'
4
+ require 'fileutils'
5
+
1
6
  unless defined?(RSpec::Core::NullReporter)
2
7
  module RSpec::Core
3
8
  class NullReporter
@@ -32,6 +37,29 @@ module RSpec::Puppet
32
37
  @filters = ['Stage[main]', 'Class[Settings]', 'Class[main]', 'Node[default]']
33
38
  end
34
39
 
40
+ def save_results
41
+ slug = "#{Digest::MD5.hexdigest(Dir.pwd)}-#{Process.pid}"
42
+ File.open(File.join(Dir.tmpdir, "rspec-puppet-coverage-#{slug}"), 'w+') do |f|
43
+ f.puts @collection.to_json
44
+ end
45
+ end
46
+
47
+ def merge_results
48
+ pattern = File.join(Dir.tmpdir, "rspec-puppet-coverage-#{Digest::MD5.hexdigest(Dir.pwd)}-*")
49
+ Dir[pattern].each do |result_file|
50
+ load_results(result_file)
51
+ FileUtils.rm(result_file)
52
+ end
53
+ end
54
+
55
+ def load_results(path)
56
+ saved_results = JSON.parse(File.read(path))
57
+ saved_results.each do |resource, data|
58
+ add(resource)
59
+ cover!(resource) if data['touched']
60
+ end
61
+ end
62
+
35
63
  def add(resource)
36
64
  if !exists?(resource) && !filtered?(resource)
37
65
  @collection[resource.to_s] = ResourceWrapper.new(resource)
@@ -70,47 +98,49 @@ module RSpec::Puppet
70
98
  end
71
99
 
72
100
  def report!(coverage_desired = nil)
73
- report = results
74
- puts <<-EOH.gsub(/^ {8}/, '')
75
-
76
- Total resources: #{report[:total]}
77
- Touched resources: #{report[:touched]}
78
- Resource coverage: #{report[:coverage]}%
79
- EOH
80
-
81
- if report[:coverage] != "100.00"
82
- puts <<-EOH.gsub(/^ {10}/, '')
83
- Untouched resources:
84
-
85
- #{
86
- untouched_resources = report[:resources].reject do |_,rsrc|
87
- rsrc[:touched]
88
- end
89
- untouched_resources.inject([]) do |memo, (name,_)|
90
- memo << " #{name}"
91
- end.sort.join("\n")
92
- }
93
- EOH
94
- if coverage_desired
95
- coverage_test(coverage_desired, report[:coverage])
101
+ if parallel_tests?
102
+ require 'parallel_tests'
103
+
104
+ if ParallelTests.first_process?
105
+ ParallelTests.wait_for_other_processes_to_finish
106
+ run_report(coverage_desired)
107
+ else
108
+ save_results
96
109
  end
110
+ else
111
+ run_report(coverage_desired)
97
112
  end
98
113
  end
99
114
 
100
- def coverage_test(coverage_desired, coverage_actual)
115
+ def parallel_tests?
116
+ !!ENV['TEST_ENV_NUMBER']
117
+ end
118
+
119
+ def run_report(coverage_desired = nil)
120
+ merge_results if ENV['TEST_ENV_NUMBER']
121
+
122
+ report = results
123
+
124
+ coverage_test(coverage_desired, report)
125
+
126
+ puts report[:text]
127
+ end
128
+
129
+ def coverage_test(coverage_desired, report)
130
+ coverage_actual = report[:coverage]
131
+ coverage_desired ||= 0
132
+
101
133
  if coverage_desired.is_a?(Numeric) && coverage_desired.to_f <= 100.00 && coverage_desired.to_f >= 0.0
102
- coverage_test = RSpec.describe("Code coverage.")
103
- coverage_results = coverage_test.example("Must be at least #{coverage_desired}% of code coverage") {
134
+ coverage_test = RSpec.describe("Code coverage")
135
+ coverage_results = coverage_test.example("must cover at least #{coverage_desired}% of resources") do
104
136
  expect( coverage_actual.to_f ).to be >= coverage_desired.to_f
105
- }
106
- coverage_test.run(RSpec::Core::NullReporter)
107
- passed = if coverage_results.execution_result.respond_to? :status then
108
- coverage_results.execution_result.status == :passed
109
- else
110
- coverage_results.execution_result[:status] == 'passed'
111
- end
112
-
113
- RSpec.configuration.reporter.example_failed coverage_results unless passed
137
+ end
138
+ coverage_test.run(RSpec.configuration.reporter)
139
+
140
+ # This is not available on RSpec 2.x
141
+ if coverage_results.execution_result.respond_to?(:pending_message)
142
+ coverage_results.execution_result.pending_message = report[:text]
143
+ end
114
144
  else
115
145
  puts "The desired coverage must be 0 <= x <= 100, not '#{coverage_desired.inspect}'"
116
146
  end
@@ -130,6 +160,19 @@ module RSpec::Puppet
130
160
  [name, wrapper.to_hash]
131
161
  end.flatten]
132
162
 
163
+ text = [
164
+ "Total resources: #{report[:total]}",
165
+ "Touched resources: #{report[:touched]}",
166
+ "Resource coverage: #{report[:coverage]}%",
167
+ ]
168
+
169
+ if report[:untouched] > 0
170
+ text += ['', 'Untouched resources:']
171
+ untouched_resources = report[:resources].reject { |_, r| r[:touched] }
172
+ text += untouched_resources.map { |name, _| " #{name}" }.sort
173
+ end
174
+ report[:text] = text.join("\n")
175
+
133
176
  report
134
177
  end
135
178
 
@@ -208,6 +251,10 @@ module RSpec::Puppet
208
251
  }
209
252
  end
210
253
 
254
+ def to_json(opts)
255
+ to_hash.to_json(opts)
256
+ end
257
+
211
258
  def touch!
212
259
  @touched = true
213
260
  end
@@ -1,6 +1,12 @@
1
1
  require 'puppet'
2
2
  require 'fileutils'
3
3
 
4
+ begin
5
+ require 'win32/dir'
6
+ rescue LoadError
7
+ nil
8
+ end
9
+
4
10
  module RSpec::Puppet
5
11
  class Setup
6
12
  def self.run(module_name=nil)
@@ -151,27 +157,40 @@ END
151
157
  safe_create_file('spec/spec_helper.rb', content)
152
158
  end
153
159
 
160
+ def self.link_to_source?(target, source)
161
+ return false unless link?(target)
162
+
163
+ link_target = Dir.respond_to?(:read_junction) ? Dir.read_junction(target) : File.readlink(target)
164
+
165
+ link_target == File.expand_path(source)
166
+ end
167
+
168
+ def self.link?(target)
169
+ Dir.respond_to?(:junction?) ? Dir.junction?(target) : File.symlink?(target)
170
+ end
171
+
154
172
  def self.safe_make_link(source, target, verbose=true)
155
- if File.exist?(target)
156
- unless File.symlink?(target) && File.readlink(target) == File.expand_path(source)
157
- $stderr.puts "!! #{target} already exists and is not a symlink"
173
+ if File.exist?(target) && !link?(target)
174
+ $stderr.puts "!! #{target} already exists and is not a symlink"
175
+ return
176
+ end
177
+
178
+ return if link_to_source?(target, source)
179
+
180
+ if Puppet::Util::Platform.windows?
181
+ output = `call mklink /J "#{target.gsub('/', '\\')}" "#{source}"`
182
+ unless $?.success?
183
+ puts output
184
+ abort
158
185
  end
159
186
  else
160
- if Puppet::Util::Platform.windows?
161
- output = `call mklink /J "#{target.gsub('/', '\\')}" "#{source}"`
162
- unless $?.success?
163
- puts output
164
- abort
165
- end
166
- else
167
- begin
168
- FileUtils.ln_s(File.expand_path(source), target)
169
- rescue Errno::EEXIST => e
170
- raise e unless File.symlink?(target) && File.readlink(target) == File.expand_path(source)
171
- end
187
+ begin
188
+ FileUtils.ln_s(File.expand_path(source), target)
189
+ rescue Errno::EEXIST => e
190
+ raise e unless link_to_source?(target, source)
172
191
  end
173
- puts " + #{target}" if verbose
174
192
  end
193
+ puts " + #{target}" if verbose
175
194
  end
176
195
 
177
196
  def self.safe_create_rakefile
metadata CHANGED
@@ -1,27 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.13
4
+ version: 2.6.14
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Tim Sharpe
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
12
+ date: 2018-07-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  description: RSpec tests for your Puppet manifests
@@ -33,64 +36,65 @@ extra_rdoc_files: []
33
36
  files:
34
37
  - CHANGELOG.md
35
38
  - README.md
36
- - bin/rspec-puppet-init
37
39
  - lib/rspec-puppet.rb
38
- - lib/rspec-puppet/adapters.rb
39
- - lib/rspec-puppet/cache.rb
40
+ - lib/rspec-puppet/matchers/create_generic.rb
41
+ - lib/rspec-puppet/matchers/allow_value.rb
42
+ - lib/rspec-puppet/matchers/compile.rb
43
+ - lib/rspec-puppet/matchers/count_generic.rb
44
+ - lib/rspec-puppet/matchers/type_matchers.rb
45
+ - lib/rspec-puppet/matchers/parameter_matcher.rb
46
+ - lib/rspec-puppet/matchers/include_class.rb
47
+ - lib/rspec-puppet/matchers/dynamic_matchers.rb
48
+ - lib/rspec-puppet/matchers/run.rb
40
49
  - lib/rspec-puppet/consts.rb
41
50
  - lib/rspec-puppet/coverage.rb
42
- - lib/rspec-puppet/errors.rb
43
51
  - lib/rspec-puppet/example.rb
52
+ - lib/rspec-puppet/adapters.rb
53
+ - lib/rspec-puppet/tasks/release_test.rb
54
+ - lib/rspec-puppet/rake_task.rb
55
+ - lib/rspec-puppet/monkey_patches.rb
56
+ - lib/rspec-puppet/errors.rb
57
+ - lib/rspec-puppet/raw_string.rb
58
+ - lib/rspec-puppet/spec_helper.rb
59
+ - lib/rspec-puppet/cache.rb
60
+ - lib/rspec-puppet/support.rb
44
61
  - lib/rspec-puppet/example/application_example_group.rb
45
62
  - lib/rspec-puppet/example/class_example_group.rb
46
- - lib/rspec-puppet/example/define_example_group.rb
47
- - lib/rspec-puppet/example/function_example_group.rb
48
63
  - lib/rspec-puppet/example/host_example_group.rb
64
+ - lib/rspec-puppet/example/type_example_group.rb
49
65
  - lib/rspec-puppet/example/provider_example_group.rb
50
66
  - lib/rspec-puppet/example/type_alias_example_group.rb
51
- - lib/rspec-puppet/example/type_example_group.rb
67
+ - lib/rspec-puppet/example/function_example_group.rb
68
+ - lib/rspec-puppet/example/define_example_group.rb
52
69
  - lib/rspec-puppet/matchers.rb
53
- - lib/rspec-puppet/matchers/allow_value.rb
54
- - lib/rspec-puppet/matchers/compile.rb
55
- - lib/rspec-puppet/matchers/count_generic.rb
56
- - lib/rspec-puppet/matchers/create_generic.rb
57
- - lib/rspec-puppet/matchers/dynamic_matchers.rb
58
- - lib/rspec-puppet/matchers/include_class.rb
59
- - lib/rspec-puppet/matchers/parameter_matcher.rb
60
- - lib/rspec-puppet/matchers/run.rb
61
- - lib/rspec-puppet/matchers/type_matchers.rb
62
- - lib/rspec-puppet/monkey_patches.rb
70
+ - lib/rspec-puppet/setup.rb
63
71
  - lib/rspec-puppet/monkey_patches/win32/registry.rb
64
72
  - lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb
65
73
  - lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb
66
- - lib/rspec-puppet/rake_task.rb
67
- - lib/rspec-puppet/raw_string.rb
68
- - lib/rspec-puppet/setup.rb
69
- - lib/rspec-puppet/spec_helper.rb
70
- - lib/rspec-puppet/support.rb
71
- - lib/rspec-puppet/tasks/release_test.rb
74
+ - bin/rspec-puppet-init
72
75
  homepage: https://github.com/rodjek/rspec-puppet/
73
76
  licenses:
74
77
  - MIT
75
- metadata: {}
76
78
  post_install_message:
77
79
  rdoc_options: []
78
80
  require_paths:
79
81
  - lib
80
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
81
84
  requirements:
82
- - - ">="
85
+ - - ! '>='
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
85
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
86
90
  requirements:
87
- - - ">="
91
+ - - ! '>='
88
92
  - !ruby/object:Gem::Version
89
93
  version: '0'
90
94
  requirements: []
91
95
  rubyforge_project:
92
- rubygems_version: 2.6.14.1
96
+ rubygems_version: 1.8.23.2
93
97
  signing_key:
94
- specification_version: 4
98
+ specification_version: 3
95
99
  summary: RSpec tests for your Puppet manifests
96
100
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 5020bbb4c2617605ec685fff03b6758f52e39618
4
- data.tar.gz: 120375f102a07f4e70137d4775db43081aeb83bf
5
- SHA512:
6
- metadata.gz: 3ce834172e14e490eabc25dfaf0b3a0232d273eb7cbb6138231731a42939bd63e5662968044b3e553511603b3d0645f75c4c2013ddb30503529792a9a0a70fe9
7
- data.tar.gz: 2e0abd0830f9c3faed1028c618b94334c7ac73ae2b88543f2db4ba38abb2698566eda4fb3b697508a88d2e7279c25002fae8765c7b37dc966adaad7d98c4d444