rspec-puppet-utils 2.0.3 → 2.0.4
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 +5 -5
- data/README.md +4 -4
- data/lib/template_harness.rb +5 -2
- data/rspec-puppet-utils.gemspec +1 -1
- data/spec/classes/template_harness_spec.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
metadata.gz: a793bb20839f6196c2ce603dcc9b8c8841b6531edf46b3ad30e06f7abd23606a9fd64928e454e5d2b7bc0badf94fd7aef662d6c75473d8278fdb51c3c4c0bc10
|
4
|
-
data.tar.gz: 8bae6014ffb663d0710e978defebed9f756d93e541265aace4e0fc225cc20b3d45cbbbbe42d5d9533d0b677f38347dd5ae5a1085c7895379b841cbc32e2155d8
|
5
2
|
SHA1:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dade7bb417a5a0a9d0729271ec800230452f8193
|
4
|
+
data.tar.gz: db8ed24e66fb1ccd37b6e3d176cc2c0bd6865ce5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33be8cf25d66aeeffd71ab9ffcbebd275c97d47511844577457c4e77fbeec59f83f9d7f45d008c39a4915c1c6391069a693f711d3a28a2ef3de8f9de282fb002
|
7
|
+
data.tar.gz: 29869351c54ecfacfefe580b1d2f29c645d537c0ff617437fb227cea172b0fc18cfe6a8ca0f9567bb92391e2a3d63280969093a9c0d2ba8e7a04bb2383562069
|
data/README.md
CHANGED
@@ -47,14 +47,14 @@ If you use let, **use `let!()` and not `let()`**, this is because lets are lazy-
|
|
47
47
|
|
48
48
|
Also if you use `let` when mocking hiera, **you can't use `:hiera` as the name due to conflicts** so you have to do something like `let!(:mock_hiera) { MockFunction.new('hiera') }`
|
49
49
|
|
50
|
-
Mocha stubs and expects:
|
50
|
+
#####Mocha stubs and expects:
|
51
51
|
`f.stub` and `f.expect` are helper methods for `f.stubs(:call)` and `f.expects(:call)`
|
52
52
|
|
53
|
-
Internally `#expect` will clear the rspec-puppet catalog cache. This is because rspec-puppet will only re-compile the catalog for a test if
|
53
|
+
Internally `#expect` will clear the rspec-puppet catalog cache. This is because rspec-puppet will only re-compile the catalog for a test if `:title`, `:params`, or `:facts` are changed. This means that if you setup an expectaion in a test, it might not be satisfied because the catalog was already compiled for a previous test, and so the functions weren't called!
|
54
54
|
|
55
|
-
Clearing the cache ensures tests aren't coupled and order dependent. The downside is that the catalog isn't cached and has to be re-compiled which slows down
|
55
|
+
Clearing the cache ensures tests aren't coupled and order dependent. The downside is that the catalog isn't cached and has to be re-compiled which slows down your tests. If you're concerned about performance and you are explicitly changing `:title`, `:params`, or `:facts` for a test, you can keep the cache intact with `f.expect(:keep_cache)`
|
56
56
|
|
57
|
-
Notes:
|
57
|
+
#####Notes:
|
58
58
|
- You always stub the `call` method as that gets called internally
|
59
59
|
- The `call` method takes an array of arguments
|
60
60
|
|
data/lib/template_harness.rb
CHANGED
@@ -16,8 +16,11 @@ module RSpecPuppetUtils
|
|
16
16
|
|
17
17
|
def run
|
18
18
|
b = @isolator.get_binding
|
19
|
-
|
20
|
-
|
19
|
+
inline = !File.exists?(@template)
|
20
|
+
template_string = inline ? @template : File.new(@template).read
|
21
|
+
template = ERB.new(template_string, 0, '-')
|
22
|
+
template.filename = File.expand_path(@template) unless inline
|
23
|
+
template.result b
|
21
24
|
end
|
22
25
|
|
23
26
|
class Isolator
|
data/rspec-puppet-utils.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = 'rspec-puppet-utils'
|
4
|
-
gem.version = '2.0.
|
4
|
+
gem.version = '2.0.4'
|
5
5
|
gem.description = 'Helper classes for mock/stub functions, templates and hierdata'
|
6
6
|
gem.summary = ''
|
7
7
|
gem.author = 'Tom Poulton'
|
@@ -45,4 +45,25 @@ describe TemplateHarness do
|
|
45
45
|
expect(harness.run).to eq 'elephant'
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'should set filename of template' do
|
49
|
+
template_path = 'spec/fixtures/templates/returns_elephant.erb'
|
50
|
+
absolute_path = File.expand_path(template_path)
|
51
|
+
|
52
|
+
fakeplate = Object.new
|
53
|
+
fakeplate.stubs(:result).returns('')
|
54
|
+
fakeplate.expects(:filename=).with(absolute_path).once
|
55
|
+
ERB.stubs(:new).returns(fakeplate)
|
56
|
+
|
57
|
+
TemplateHarness.new(template_path).run
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should not set filename of inline template' do
|
61
|
+
fakeplate = Object.new
|
62
|
+
fakeplate.stubs(:result).returns('')
|
63
|
+
fakeplate.expects(:filename=).never
|
64
|
+
ERB.stubs(:new).returns(fakeplate)
|
65
|
+
|
66
|
+
TemplateHarness.new('<%= "" %>').run
|
67
|
+
end
|
68
|
+
|
48
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Poulton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-02 00:00:00 Z
|
13
13
|
dependencies: []
|
14
14
|
|
15
15
|
description: Helper classes for mock/stub functions, templates and hierdata
|