poise 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile +0 -2
  5. data/lib/poise.rb +3 -1
  6. data/lib/poise/backports.rb +27 -0
  7. data/lib/poise/backports/not_passed.rb +52 -0
  8. data/lib/poise/helpers.rb +1 -0
  9. data/lib/poise/helpers/chefspec_matchers.rb +5 -1
  10. data/lib/poise/helpers/inversion.rb +36 -13
  11. data/lib/poise/helpers/option_collector.rb +15 -4
  12. data/lib/poise/helpers/resource_name.rb +1 -1
  13. data/lib/poise/helpers/resource_subclass.rb +81 -0
  14. data/lib/poise/helpers/subresources/child.rb +50 -9
  15. data/lib/poise/helpers/subresources/container.rb +33 -6
  16. data/lib/poise/resource.rb +3 -1
  17. data/lib/poise/subcontext/resource_collection.rb +20 -1
  18. data/lib/poise/utils.rb +79 -7
  19. data/lib/poise/utils/resource_provider_mixin.rb +2 -2
  20. data/lib/poise/version.rb +1 -1
  21. data/test/spec/backports/not_passed_spec.rb +29 -0
  22. data/test/spec/helpers/chefspec_matchers_spec.rb +17 -0
  23. data/test/spec/helpers/inversion_spec.rb +72 -0
  24. data/test/spec/helpers/lwrp_polyfill_spec.rb +9 -0
  25. data/test/spec/helpers/option_collector_spec.rb +66 -30
  26. data/test/spec/helpers/resource_name_spec.rb +15 -2
  27. data/test/spec/helpers/resource_subclass_spec.rb +97 -0
  28. data/test/spec/helpers/subresources/child_spec.rb +234 -2
  29. data/test/spec/helpers/subresources/container_spec.rb +37 -0
  30. data/test/spec/resource_spec.rb +31 -2
  31. data/test/spec/subcontext/resource_collection_spec.rb +99 -0
  32. data/test/spec/utils/resource_provider_mixin_spec.rb +22 -0
  33. data/test/spec/utils_spec.rb +187 -1
  34. metadata +11 -3
  35. data/Berksfile.lock +0 -10
@@ -73,7 +73,7 @@ describe Poise::Resource do
73
73
  end # /context with an optional parent
74
74
  end # /describe #poise_subresource
75
75
 
76
- context 'with fused' do
76
+ describe '#poise_fused' do
77
77
  resource(:poise_test) do
78
78
  include described_class
79
79
  poise_fused
@@ -81,5 +81,34 @@ describe Poise::Resource do
81
81
 
82
82
  it { is_expected.to include Poise::Resource }
83
83
  it { is_expected.to include Poise::Helpers::Fused }
84
- end # /context with fused
84
+ end # /describe #poise_fused
85
+
86
+ describe '#poise_inversion' do
87
+ context 'with an options resource' do
88
+ resource(:poise_test) do
89
+ include described_class
90
+ poise_inversion
91
+ provides(:poise_test)
92
+ Halite::SpecHelper::Patcher.post_create_cleanup(:poise_test_options, inversion_options_resource_class)
93
+ Halite::SpecHelper::Patcher.post_create_cleanup(:poise_test_options, inversion_options_provider_class)
94
+ end
95
+ it { is_expected.to include Poise::Resource }
96
+ it { is_expected.to include Poise::Helpers::Inversion }
97
+ its(:inversion_options_resource_class) { is_expected.to be_truthy }
98
+ its(:inversion_options_provider_class) { is_expected.to be_truthy }
99
+ end # /context with an options resource
100
+
101
+ context 'without an options resource' do
102
+ resource(:poise_test) do
103
+ include described_class
104
+ poise_inversion(false)
105
+ provides(:poise_test)
106
+ end
107
+ it { is_expected.to include Poise::Resource }
108
+ it { is_expected.to include Poise::Helpers::Inversion }
109
+ its(:inversion_options_resource_class) { is_expected.to be nil }
110
+ its(:inversion_options_provider_class) { is_expected.to be nil }
111
+ it { expect { Chef::Resource.resource_for_node(:poise_test_options, chef_run.node) }.to raise_error Chef::Exceptions::NoSuchResourceType }
112
+ end # /context without an options resource
113
+ end # /describe #poise_inversion
85
114
  end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe Poise::Subcontext::ResourceCollection do
20
+ let(:top) { Chef::ResourceCollection.new }
21
+ let(:sub) { described_class.new(top) }
22
+ let(:inner) { described_class.new(sub) }
23
+ let(:sibling) { described_class.new(top) }
24
+ subject(:subject_context) { sub }
25
+
26
+ # Helper for use in #before.
27
+ def res(name)
28
+ Chef::Resource::RubyBlock.new(name, nil)
29
+ end
30
+
31
+ # Populate the various collections with test data.
32
+ before do
33
+ top << res('top1')
34
+ top << res('top2')
35
+ sub << res('sub1')
36
+ sub << res('sub2')
37
+ inner << res('inner1')
38
+ inner << res('inner2')
39
+ sibling << res('sibling1')
40
+ sibling << res('sibling2')
41
+ end
42
+
43
+ describe '#lookup' do
44
+ let(:name) { '' }
45
+ subject { subject_context.lookup("ruby_block[#{name}]") }
46
+
47
+ context 'with a resource in the subcontext' do
48
+ let(:name) { 'sub1' }
49
+ it { is_expected.to be_a Chef::Resource }
50
+ end # /context with a resource in the subcontext
51
+
52
+ context 'with a resource in a parent context' do
53
+ let(:name) { 'top1' }
54
+ it { is_expected.to be_a Chef::Resource }
55
+ end # /context with a resource in a parent context
56
+
57
+ context 'with a resource in a sibling context' do
58
+ let(:name) { 'sibling1' }
59
+ it { expect { subject }.to raise_error Chef::Exceptions::ResourceNotFound }
60
+ end # /context with a resource in a sibling context
61
+
62
+ context 'with a resource in a nested context' do
63
+ let(:name) { 'inner1' }
64
+ it { expect { subject }.to raise_error Chef::Exceptions::ResourceNotFound }
65
+ end # /context with a resource in a nested context
66
+ end # /describe #lookup
67
+
68
+ describe '#recursive_each' do
69
+ subject do
70
+ [].tap do |ary|
71
+ subject_context.recursive_each do |res|
72
+ ary << res.name
73
+ end
74
+ end
75
+ end
76
+ it { is_expected.to eq %w{top1 top2 sub1 sub2} }
77
+
78
+ context 'from a deeply nested context' do
79
+ let(:subject_context) { inner }
80
+ it { is_expected.to eq %w{top1 top2 sub1 sub2 inner1 inner2} }
81
+ end # /context from a deeply nested context
82
+ end # /describe #recursive_each
83
+
84
+ describe '#reverse_recursive_each' do
85
+ subject do
86
+ [].tap do |ary|
87
+ subject_context.reverse_recursive_each do |res|
88
+ ary << res.name
89
+ end
90
+ end
91
+ end
92
+ it { is_expected.to eq %w{sub2 sub1 top2 top1} }
93
+
94
+ context 'from a deeply nested context' do
95
+ let(:subject_context) { inner }
96
+ it { is_expected.to eq %w{inner2 inner1 sub2 sub1 top2 top1} }
97
+ end # /context from a deeply nested context
98
+ end # /describe #reverse_recursive_each
99
+ end
@@ -59,6 +59,16 @@ module ResourceProviderMixinTest
59
59
  include Test
60
60
  include Test2
61
61
  end
62
+
63
+ module Mixins
64
+ module Resource
65
+ include Test
66
+ end
67
+
68
+ module Provider
69
+ include Test
70
+ end
71
+ end
62
72
  end
63
73
 
64
74
  describe Poise::Utils::ResourceProviderMixin do
@@ -85,4 +95,16 @@ describe Poise::Utils::ResourceProviderMixin do
85
95
  it { is_expected.to be < ResourceProviderMixinTest::Test2::Provider }
86
96
  end
87
97
  end # /context with nested usage
98
+
99
+ context 'with a mixin' do
100
+ context 'in a resource' do
101
+ subject { ResourceProviderMixinTest::Mixins::Resource }
102
+ it { is_expected.to include ResourceProviderMixinTest::Test::Resource }
103
+ end
104
+
105
+ context 'in a provider' do
106
+ subject { ResourceProviderMixinTest::Mixins::Provider }
107
+ it { is_expected.to include ResourceProviderMixinTest::Test::Provider }
108
+ end
109
+ end # /context with a mixin
88
110
  end
@@ -17,10 +17,52 @@
17
17
  require 'spec_helper'
18
18
  require 'chef/cookbook_version'
19
19
 
20
+ module PoiseUtilsSpecTopLevel
21
+ module ClassMethods
22
+ def something(name=nil)
23
+ @something = name if name
24
+ @something
25
+ end
26
+
27
+ def included(klass)
28
+ super
29
+ klass.extend(ClassMethods)
30
+ end
31
+ end
32
+
33
+ extend ClassMethods
34
+ end
35
+
36
+ Poise::Utils.parameterized_module(PoiseUtilsSpecTopLevel) do |name|
37
+ something(name)
38
+ end
39
+
40
+ module PoiseUtilsSpecNested
41
+ module Inner
42
+ module ClassMethods
43
+ def something(name=nil)
44
+ @something = name if name
45
+ @something
46
+ end
47
+
48
+ def included(klass)
49
+ super
50
+ klass.extend(ClassMethods)
51
+ end
52
+ end
53
+
54
+ extend ClassMethods
55
+ end
56
+ end
57
+
58
+ Poise::Utils.parameterized_module(PoiseUtilsSpecNested::Inner) do |name|
59
+ something(name)
60
+ end
61
+
20
62
  describe Poise::Utils do
21
63
  describe '.find_cookbook_name' do
22
64
  let(:cookbooks) { [] }
23
- let(:run_context) { instance_double('Chef::RunContext', cookbook_collection: cookbooks.inject({}) {|memo, ver| memo[ver.name] = ver; memo })}
65
+ let(:run_context) { instance_double('Chef::RunContext', cookbook_collection: cookbooks.inject({}) {|memo, ver| memo[ver.name] = ver; memo }, node: {})}
24
66
  let(:filename) { '/test/my_cookbook/libraries/default.rb' }
25
67
  subject { described_class.find_cookbook_name(run_context, filename) }
26
68
 
@@ -194,5 +236,149 @@ describe Poise::Utils do
194
236
 
195
237
  its(:poise_test_val) { is_expected.to be_nil }
196
238
  end # /context with no value set
239
+
240
+ context 'with a branching ancestor tree' do
241
+ let(:mod_child1) do
242
+ parent = mod_parent
243
+ Module.new do
244
+ include parent
245
+ poise_test_val(:child1)
246
+ end
247
+ end
248
+ let(:mod_child2) do
249
+ parent = mod_parent
250
+ Module.new do
251
+ include parent
252
+ end
253
+ end
254
+ subject do
255
+ mod1 = mod_child1
256
+ mod2 = mod_child2
257
+ Class.new do
258
+ include mod1
259
+ include mod2
260
+ end
261
+ end
262
+
263
+ its(:poise_test_val) { is_expected.to eq :child1 }
264
+
265
+ context 'with ignorable values' do
266
+ let(:mod_parent) do
267
+ Module.new do
268
+ class_methods = Module.new do
269
+ def poise_test_val(val=nil)
270
+ if val
271
+ @poise_test_val = val
272
+ end
273
+ @poise_test_val || Poise::Utils.ancestor_send(self, :poise_test_val, ignore: [true])
274
+ end
275
+
276
+ define_method(:included) do |klass|
277
+ super(klass)
278
+ klass.extend(class_methods)
279
+ end
280
+ end
281
+
282
+ extend class_methods
283
+ end
284
+ end
285
+ let(:mod_child2) do
286
+ parent = mod_parent
287
+ Module.new do
288
+ include parent
289
+ poise_test_val(true)
290
+ end
291
+ end
292
+
293
+ its(:poise_test_val) { is_expected.to eq :child1 }
294
+ end # /context with ignorable values
295
+ end # /context with a branching ancestor tree
197
296
  end # /describe .ancestor_send
297
+
298
+ describe '.parameterized_module' do
299
+ context 'with a top-level module' do
300
+ subject do
301
+ Module.new do
302
+ include PoiseUtilsSpecTopLevel('top')
303
+ end
304
+ end
305
+
306
+ its(:something) { is_expected.to eq 'top' }
307
+ it { expect(PoiseUtilsSpecTopLevel('top').name).to eq 'PoiseUtilsSpecTopLevel' }
308
+ end # /context with a top-level module
309
+
310
+ context 'with a nested module' do
311
+ subject do
312
+ Module.new do
313
+ include PoiseUtilsSpecNested::Inner('inner')
314
+ end
315
+ end
316
+
317
+ its(:something) { is_expected.to eq 'inner' }
318
+ it { expect(PoiseUtilsSpecNested::Inner('inner').name).to eq 'PoiseUtilsSpecNested::Inner' }
319
+ end # /context with a nested module
320
+
321
+ context 'with an anonymous module' do
322
+ subject { Poise::Utils.parameterized_module(Module.new) }
323
+ it { expect { subject }.to raise_error Poise::Error }
324
+ end # /context with an anonymous module
325
+
326
+ context 'with the wrong arugments' do
327
+ subject { PoiseUtilsSpecTopLevel('top', 'other') }
328
+ it { expect { subject }.to raise_error ArgumentError }
329
+ end # /context with the wrong arugments
330
+ end # /describe .parameterized_module
331
+
332
+ describe '.check_block_arity!' do
333
+ let(:block) { }
334
+ let(:args) { }
335
+ subject { Poise::Utils.send(:check_block_arity!, block, args) }
336
+
337
+ context 'with a positive arity' do
338
+ let(:block) do
339
+ proc {|a, b| nil }
340
+ end
341
+
342
+ context 'with 0 arguments' do
343
+ let(:args) { [] }
344
+ it { expect { subject }.to raise_error ArgumentError, /wrong number of arguments \(0 for 2\)/ }
345
+ end # /context with 0 arguments
346
+
347
+ context 'with 1 argument' do
348
+ let(:args) { [1] }
349
+ it { expect { subject }.to raise_error ArgumentError, /wrong number of arguments \(1 for 2\)/ }
350
+ end # /context with 1 argument
351
+
352
+ context 'with 2 arguments' do
353
+ let(:args) { [1, 2] }
354
+ it { expect { subject }.to_not raise_error }
355
+ end # /context with 2 arguments
356
+
357
+ context 'with 3 arguments' do
358
+ let(:args) { [1, 2, 3] }
359
+ it { expect { subject }.to raise_error ArgumentError, /wrong number of arguments \(3 for 2\)/ }
360
+ end # /context with 3 arguments
361
+ end # /context with a positive arity
362
+
363
+ context 'with a negative arity' do
364
+ let(:block) do
365
+ proc {|a, *b| nil }
366
+ end
367
+
368
+ context 'with 0 arguments' do
369
+ let(:args) { [] }
370
+ it { expect { subject }.to raise_error ArgumentError, /wrong number of arguments \(0 for 1\+\)/ }
371
+ end # /context with 0 arguments
372
+
373
+ context 'with 1 argument' do
374
+ let(:args) { [1] }
375
+ it { expect { subject }.to_not raise_error }
376
+ end # /context with 1 argument
377
+
378
+ context 'with 2 arguments' do
379
+ let(:args) { [1, 2] }
380
+ it { expect { subject }.to_not raise_error }
381
+ end # /context with 2 arguments
382
+ end # /context with a negative arity
383
+ end # /describe .check_block_arity!
198
384
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poise
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite
@@ -52,13 +52,14 @@ files:
52
52
  - ".travis.yml"
53
53
  - ".yardopts"
54
54
  - Berksfile
55
- - Berksfile.lock
56
55
  - CHANGELOG.md
57
56
  - Gemfile
58
57
  - LICENSE
59
58
  - README.md
60
59
  - Rakefile
61
60
  - lib/poise.rb
61
+ - lib/poise/backports.rb
62
+ - lib/poise/backports/not_passed.rb
62
63
  - lib/poise/error.rb
63
64
  - lib/poise/helpers.rb
64
65
  - lib/poise/helpers/chefspec_matchers.rb
@@ -74,6 +75,7 @@ files:
74
75
  - lib/poise/helpers/option_collector.rb
75
76
  - lib/poise/helpers/resource_cloning.rb
76
77
  - lib/poise/helpers/resource_name.rb
78
+ - lib/poise/helpers/resource_subclass.rb
77
79
  - lib/poise/helpers/subcontext_block.rb
78
80
  - lib/poise/helpers/subresources.rb
79
81
  - lib/poise/helpers/subresources/child.rb
@@ -106,6 +108,7 @@ files:
106
108
  - test/gemfiles/master.gemfile
107
109
  - test/integration/default/serverspec/default_spec.rb
108
110
  - test/integration/default/serverspec/inversion_spec.rb
111
+ - test/spec/backports/not_passed_spec.rb
109
112
  - test/spec/helpers/chefspec_matchers_spec.rb
110
113
  - test/spec/helpers/defined_in_spec.rb
111
114
  - test/spec/helpers/fused_spec.rb
@@ -118,6 +121,7 @@ files:
118
121
  - test/spec/helpers/option_collector_spec.rb
119
122
  - test/spec/helpers/resource_cloning_spec.rb
120
123
  - test/spec/helpers/resource_name_spec.rb
124
+ - test/spec/helpers/resource_subclass_spec.rb
121
125
  - test/spec/helpers/subcontext_block_spec.rb
122
126
  - test/spec/helpers/subresources/child_spec.rb
123
127
  - test/spec/helpers/subresources/container_spec.rb
@@ -126,6 +130,7 @@ files:
126
130
  - test/spec/provider_spec.rb
127
131
  - test/spec/resource_spec.rb
128
132
  - test/spec/spec_helper.rb
133
+ - test/spec/subcontext/resource_collection_spec.rb
129
134
  - test/spec/utils/resource_provider_mixin_spec.rb
130
135
  - test/spec/utils_spec.rb
131
136
  homepage: https://github.com/poise/poise
@@ -170,6 +175,7 @@ test_files:
170
175
  - test/gemfiles/master.gemfile
171
176
  - test/integration/default/serverspec/default_spec.rb
172
177
  - test/integration/default/serverspec/inversion_spec.rb
178
+ - test/spec/backports/not_passed_spec.rb
173
179
  - test/spec/helpers/chefspec_matchers_spec.rb
174
180
  - test/spec/helpers/defined_in_spec.rb
175
181
  - test/spec/helpers/fused_spec.rb
@@ -182,6 +188,7 @@ test_files:
182
188
  - test/spec/helpers/option_collector_spec.rb
183
189
  - test/spec/helpers/resource_cloning_spec.rb
184
190
  - test/spec/helpers/resource_name_spec.rb
191
+ - test/spec/helpers/resource_subclass_spec.rb
185
192
  - test/spec/helpers/subcontext_block_spec.rb
186
193
  - test/spec/helpers/subresources/child_spec.rb
187
194
  - test/spec/helpers/subresources/container_spec.rb
@@ -190,6 +197,7 @@ test_files:
190
197
  - test/spec/provider_spec.rb
191
198
  - test/spec/resource_spec.rb
192
199
  - test/spec/spec_helper.rb
200
+ - test/spec/subcontext/resource_collection_spec.rb
193
201
  - test/spec/utils/resource_provider_mixin_spec.rb
194
202
  - test/spec/utils_spec.rb
195
203
  has_rdoc: