rspec-puppet-utils 2.0.2 → 2.0.3

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
- SHA1:
3
- data.tar.gz: b0dfaaec1638d3f1d372730e2e988c64e5d9223a
4
- metadata.gz: 49631403a559b447615d123c159513b69bea340d
5
2
  SHA512:
6
- data.tar.gz: d268e8294f419de6ef69486b865b55e3fcfa1bf11d6b5716213154bf306f4f4bc102f0852e84804ae64f453593ce0a3c307704fbf218003fe5bd2735890a8467
7
- metadata.gz: a9c3ec8679ca46e3cf44153a62fe5881883247f92af38fe473da8b42bf227722971c8223d3bf9da95e56f3c9c8d01e39e0ab989f0103851026412988bde8e8dd
3
+ metadata.gz: a793bb20839f6196c2ce603dcc9b8c8841b6531edf46b3ad30e06f7abd23606a9fd64928e454e5d2b7bc0badf94fd7aef662d6c75473d8278fdb51c3c4c0bc10
4
+ data.tar.gz: 8bae6014ffb663d0710e978defebed9f756d93e541265aace4e0fc225cc20b3d45cbbbbe42d5d9533d0b677f38347dd5ae5a1085c7895379b841cbc32e2155d8
5
+ SHA1:
6
+ metadata.gz: 0e9fcf15482e816c286f0cbea058e43c7e704427
7
+ data.tar.gz: 7de926971e6a20fa05e1b6a89a7e09c64affced2
data/README.md CHANGED
@@ -47,8 +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:
51
+ `f.stub` and `f.expect` are helper methods for `f.stubs(:call)` and `f.expects(:call)`
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 the title, params, facts, or code is changed. This means that functions are only called when these are changed, so if you setup an expectaion in a test, it might not be satisfied because the catalog was already compiled for a previous test.
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 the tests. So if you're concerned about performance and you are explicitly changing the title or params (or facts or code) for a test you can keep the cache intact with `f.expect(:keep_cache)`
56
+
50
57
  Notes:
51
- - `f.stub` and `f.expect` are helper methods for `f.stubs(:call)` and `f.expects(:call)`
52
58
  - You always stub the `call` method as that gets called internally
53
59
  - The `call` method takes an array of arguments
54
60
 
data/lib/mock_function.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require 'puppet'
2
2
  require 'mocha'
3
3
 
4
+ module RSpec::Puppet
5
+ module Support
6
+ def self.clear_cache
7
+ @@cache = {}
8
+ end
9
+ end
10
+ end
11
+
4
12
  module RSpecPuppetUtils
5
13
 
6
14
  class MockFunction
@@ -24,7 +32,8 @@ module RSpecPuppetUtils
24
32
  self.stubs(:call)
25
33
  end
26
34
 
27
- def expect
35
+ def expect(*args)
36
+ RSpec::Puppet::Support.clear_cache unless args.include? :keep_cache
28
37
  self.expects(:call)
29
38
  end
30
39
 
@@ -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.2'
4
+ gem.version = '2.0.3'
5
5
  gem.description = 'Helper classes for mock/stub functions, templates and hierdata'
6
6
  gem.summary = ''
7
7
  gem.author = 'Tom Poulton'
@@ -100,7 +100,23 @@ describe MockFunction do
100
100
  expectation = func.expect
101
101
  expect(expectation).to be_a Mocha::Expectation
102
102
  expect(expectation.matches_method? :call).to eq true
103
- func.call [nil] # satisfy the expect we just created!
103
+ func.call [nil] # satisfy the expect we just created on #call!
104
+ end
105
+
106
+ it 'should clear rspec puppet cache' do
107
+ RSpec::Puppet::Support.expects(:clear_cache).once
108
+ func.expect
109
+ func.call [nil] # satisfy the expect we just created on #call!
110
+ end
111
+
112
+ context 'when :keep_cache is set' do
113
+
114
+ it 'should not clear rspec puppet cache' do
115
+ RSpec::Puppet::Support.expects(:clear_cache).never
116
+ func.expect(:keep_cache)
117
+ func.call [nil] # satisfy the expect we just created on #call!
118
+ end
119
+
104
120
  end
105
121
 
106
122
  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.2
4
+ version: 2.0.3
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-03-27 00:00:00 Z
12
+ date: 2014-06-17 00:00:00 Z
13
13
  dependencies: []
14
14
 
15
15
  description: Helper classes for mock/stub functions, templates and hierdata