simple_approvals-chefspec 1.0.1 → 1.0.2

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
- SHA1:
3
- metadata.gz: e4d417ea8ccd1d5e97bcae8b064a93ed956750d3
4
- data.tar.gz: 2872719e87dffba61ec1feea62e8aeb30aeb2728
2
+ SHA256:
3
+ metadata.gz: f09a4f70a83e0c647f63ec39b38ccdf7382271dc532eab8a41b93668d86efc0a
4
+ data.tar.gz: b692894f7d4abe9c4500e58dfa641d0b89a5aaab1804ee714d2900b219718ecc
5
5
  SHA512:
6
- metadata.gz: 84a7c512cbe4c1826345fd62b25a501a4611e1f4a8562f55706a2368c711a2d5f8f52292fcca45bc72a61c2c92fed8f4dc8eca6d7667b6a88dc746482e23aca8
7
- data.tar.gz: edd6cae4289d79cf3c5738d785cc9284eee8bec79f81ff946454a7bf244997782e698e547686fdc7c190955de891a85e59393d18a011ec18c3b5899c749dd99c
6
+ metadata.gz: 8cdac16c42c407e1334ecae4d0e6209470807ddc7d2497cbad0d35a9cc238c19435125d15fd8b082ad624f324a286808a8d871d7fce32d8173805b6af1592858
7
+ data.tar.gz: 53b5c31907d0b1f2f6a81941aa96100e01cb49680cf2993e7e526bc33de7474c754c7e863f300209eae7fd2b26629d7f88bd19d918d0490257212407fac2a270
@@ -0,0 +1,99 @@
1
+ require 'rspec'
2
+ require 'chefspec'
3
+ require 'simple_approvals'
4
+
5
+ module RSpec
6
+ module Core
7
+ # open up ExampleGroup to add template approval helpers
8
+ class ExampleGroup
9
+ class << self
10
+ # This defines a batch of approval expectations which will be executed
11
+ # for each template, because each template can fail for multiple reasons:
12
+ # - not being defined in a recipe (or being defined with a different path)
13
+ # - not rendering in the cookbook (i.e. file does not exist where expected)
14
+ # - rendering with unexpected content
15
+ shared_examples_for 'an approved chef template' do |file|
16
+ describe file[:expected_path] do
17
+ if file[:template]
18
+ it 'defines the template resource' do
19
+ expect(chef_run).to create_template(file[:expected_path])
20
+ end
21
+ end
22
+
23
+ it 'renders the expected file' do
24
+ expect(chef_run).to render_file(file[:expected_path])
25
+ end
26
+
27
+ it 'renders the expected file with the expected content' do
28
+ verifier = Approvals.chef_template_verifier_for(file[:expected_path], file[:approved_path], scrubber: file[:scrubber], keep_received_file: file[:keep_received_file])
29
+ expect(chef_run).to render_file(file[:expected_path]).with_content(verifier)
30
+ end
31
+ end
32
+ end
33
+
34
+ # verify one template:
35
+ #
36
+ # verify_chef_template(expected_path: '', approved path: '')
37
+ #
38
+ def verify_chef_template(**file)
39
+ file[:template] = true
40
+ file[:scrubber] = ->(rendered_content) { yield rendered_content } if block_given?
41
+ verify_chef_file(**file)
42
+ end
43
+
44
+ def verify_chef_file(**file)
45
+ file[:scrubber] = ->(rendered_content) { yield rendered_content } if block_given?
46
+ include_examples 'an approved chef template', file
47
+ end
48
+
49
+ # verify a set of templates:
50
+ #
51
+ # verify_chef_templates(
52
+ # { expected_path: '',
53
+ # approved path: ''
54
+ # },
55
+ # { expected_path: ''
56
+ # approved path: ''
57
+ # }
58
+ # )
59
+ #
60
+ # note: this requires that rubocop is configued like this:
61
+ #
62
+ # BracesAroundHashParameters:
63
+ # EnforcedStyle: context_dependent
64
+ #
65
+ # which is taken care of in the shared lib/.chef-rubocop.yml
66
+ #
67
+ def verify_chef_templates(*specs)
68
+ specs.each do |file|
69
+ file[:scrubber] = ->(rendered_content) { yield rendered_content } if block_given?
70
+ file[:template] = true
71
+ verify_chef_file(file)
72
+ end
73
+ end
74
+
75
+ def verify_chef_files(*specs)
76
+ specs.each do |file|
77
+ file[:scrubber] = ->(rendered_content) { yield rendered_content } if block_given?
78
+ verify_chef_file(file)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ # open SimpleApprovals::Approvals and add a ChefSpec-specific helper
87
+ class Approvals
88
+ class << self
89
+ def chef_template_verifier_for(expected_path, approved_path, **options)
90
+ options[:message_override] = %(expected Chef run to render "#{expected_path}" matching "#{approved_path}")
91
+
92
+ proc do |rendered_content|
93
+ rendered_content = yield(rendered_content) if block_given?
94
+ rendered_content = options[:scrubber].call(rendered_content) if options[:scrubber]
95
+ verify(rendered_content, approved_path, **options)
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1 @@
1
+ require 'simple_approvals/chefspec/approvals'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_approvals-chefspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Alpert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,6 +145,8 @@ extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
147
  - README.md
148
+ - lib/simple_approvals/chefspec.rb
149
+ - lib/simple_approvals/chefspec/approvals.rb
148
150
  homepage: https://github.com/davidalpert/simple_approvals-chefspec/
149
151
  licenses: []
150
152
  metadata: {}
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  requirements: []
166
168
  rubyforge_project:
167
- rubygems_version: 2.6.11
169
+ rubygems_version: 2.7.9
168
170
  signing_key:
169
171
  specification_version: 4
170
172
  summary: ''