halite 1.0.7 → 1.0.8

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
2
  SHA1:
3
- metadata.gz: 17db882da6b0bae3c6e9ce2b831d14ae2c5807c7
4
- data.tar.gz: 5a0968925d77b2d5c18e2185aa1fa82bdd21adda
3
+ metadata.gz: f892bb4f8c0e111fef64f6116f3e2568a52ca35a
4
+ data.tar.gz: 3b71aeff4cefc32a256ad6f3b34c1b9b6cae538f
5
5
  SHA512:
6
- metadata.gz: 6262b355b9183ebb3d365a98dd477d6dba0235226bbf7aa48023b560c7c9afe670149cff67517f4933be6cef47549c07bf99b41dcd44e28a843b4bfce24d906c
7
- data.tar.gz: 46d28077eac059e3137dbf792e6fa5ccbc00751ae17d65f6f8dd976eb20ce4b22726683fc9e96a2beaa235d424f45ea692f2ae154d7c2b8bf5322623c3f04598
6
+ metadata.gz: 5e09f81f9f0df32a793d2bd8efd63d99a54cf24a907f14ff35635b6d771f7631539434de8ca0a23e24817690b9e4f7b2b298010f2f306165ed9b9af8b30e02ca
7
+ data.tar.gz: 87a8a9d98dff4d5864b19aab65e4f72ee10fde8240755e1f1fb0a0823e832d1f4afb7edaf5d61bbe701c4daf0d91ca4fbca5774baedc935cbf5e3f70be6061dc
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.8
4
+
5
+ * Expose `example_group` inside `SpecHelper`-created resources and providers.
6
+ * Handle `StubSpecifications` in the gem environment.
7
+
3
8
  ## v1.0.7
4
9
 
5
10
  * More fixes for Chef 12.4.1.
data/README.md CHANGED
@@ -160,6 +160,41 @@ These helper resources and providers are only available within the scope of
160
160
  recipes defined on that example group or groups nested inside it. Helper
161
161
  resources are automatically `step_into`'d.
162
162
 
163
+ ## Using a Pre-release Version of a Cookbook
164
+
165
+ When a Halite-based cookbook is released, a converted copy is generally uploaded
166
+ to [the Supermarket](https://supermarket.chef.io/). To use unreleased versions,
167
+ you need to pull in the code from git via bundler and then tell the Berkshelf
168
+ extension to convert it for you.
169
+
170
+ To grab the pre-release gem, add a line like the following to your Gemfile:
171
+
172
+ ```ruby
173
+ gem 'poise-application', github: 'poise/application'
174
+ ```
175
+
176
+ You will need one `gem` line for each Halite-based cookbook you want to use,
177
+ possibly including dependencies if you want to use pre-release versions of
178
+ those as well.
179
+
180
+ Next you need to use Berkshelf to convert the gem to its cookbook form:
181
+
182
+ ```ruby
183
+ source 'https://supermarket.chef.io/'
184
+ extension 'halite'
185
+ cookbook 'application', gem: 'poise-application'
186
+ ```
187
+
188
+ Again you will need one `cookbook` line per Halite based cookbook you want to
189
+ use. Also make sure to check the correct names for the gem and cookbook, they
190
+ may not be the same though for other Poise cookbooks they generally follow the
191
+ same pattern.
192
+
193
+ If you are using something that integrates with Berkshelf like Test-Kitchen or
194
+ ChefSpec, this is all you need to do. You could use `berks upload` to push a
195
+ converted copy of all cookbooks to a Chef Server, though running pre-release
196
+ code in production should be done with great care.
197
+
163
198
  ## License
164
199
 
165
200
  Copyright 2015, Noah Kantrowitz
@@ -35,6 +35,8 @@ module Halite
35
35
  def initialize(name, version=nil)
36
36
  # Allow passing a Dependency by just grabbing its spec.
37
37
  name = dependency_to_spec(name) if name.is_a?(::Gem::Dependency)
38
+ # Stubs don't load enough data for us, grab the real spec. RIP IOPS.
39
+ name = name.to_spec if name.is_a?(::Gem::StubSpecification)
38
40
  if name.is_a?(::Gem::Specification)
39
41
  raise Error.new("Cannot pass version when using an explicit specficiation") if version
40
42
  @spec = name
@@ -261,8 +261,8 @@ module Halite
261
261
  def resource(name, auto: true, parent: Chef::Resource, step_into: true, unwrap_notifying_block: true, defined_at: caller[0], &block)
262
262
  parent = resources[parent] if parent.is_a?(Symbol)
263
263
  raise Halite::Error.new("Parent class for #{name} is not a class: #{parent.inspect}") unless parent.is_a?(Class)
264
- # Pull out the example metadata for use in the class.
265
- metadata = self.metadata
264
+ # Pull out the example group for use in the class.
265
+ example_group = self
266
266
  # Create the resource class.
267
267
  resource_class = Class.new(parent) do
268
268
  # Make the anonymous class pretend to have a name.
@@ -276,23 +276,26 @@ module Halite
276
276
  end
277
277
 
278
278
  # Create magic delegators for various metadata.
279
- %i{described_class}.each do |key|
280
- define_method(key) { metadata[key] }
281
- define_singleton_method(key) { metadata[key] }
279
+ {
280
+ example_group: example_group,
281
+ described_class: example_group.metadata[:described_class],
282
+ }.each do |key, value|
283
+ define_method(key) { value }
284
+ define_singleton_method(key) { value }
282
285
  end
283
286
 
284
287
  # Evaluate the class body.
285
288
  class_exec(&block) if block
286
289
 
287
-
288
290
  # Optional initialization steps. Disable for special unicorn tests.
289
291
  if auto
290
292
  # Fill in a :run action by default.
291
293
  old_init = instance_method(:initialize)
292
294
  define_method(:initialize) do |*args|
293
- # Fill in the resource name because I know it
294
- @resource_name = name.to_sym
295
295
  old_init.bind(self).call(*args)
296
+ # Fill in the resource name because I know it, but don't
297
+ # overwrite because a parent might have done this already.
298
+ @resource_name = name.to_sym
296
299
  # ChefSpec doesn't seem to work well with action :nothing
297
300
  if Array(@action) == [:nothing]
298
301
  @action = :run
@@ -358,8 +361,8 @@ module Halite
358
361
  def provider(name, auto: true, rspec: true, parent: Chef::Provider, defined_at: caller[0], &block)
359
362
  parent = providers[parent] if parent.is_a?(Symbol)
360
363
  raise Halite::Error.new("Parent class for #{name} is not a class: #{options[:parent].inspect}") unless parent.is_a?(Class)
361
- # Pull out the example metadata for use in the class.
362
- metadata = self.metadata
364
+ # Pull out the example group for use in the class.
365
+ example_group = self
363
366
  # Create the provider class.
364
367
  provider_class = Class.new(parent) do
365
368
  # Pull in RSpec expectations.
@@ -389,9 +392,12 @@ module Halite
389
392
  end
390
393
 
391
394
  # Create magic delegators for various metadata.
392
- %i{described_class}.each do |key|
393
- define_method(key) { metadata[key] }
394
- define_singleton_method(key) { metadata[key] }
395
+ {
396
+ example_group: example_group,
397
+ described_class: example_group.metadata[:described_class],
398
+ }.each do |key, value|
399
+ define_method(key) { value }
400
+ define_singleton_method(key) { value }
395
401
  end
396
402
 
397
403
  # Evaluate the class body.
@@ -59,6 +59,8 @@ module Halite
59
59
  # @param klass [Class] Newly created class.
60
60
  # @return [void]
61
61
  def self.post_create_cleanup(name, klass)
62
+ # Remove from DSL.
63
+ Chef::DSL::Resources.remove_resource_dsl(name) if defined?(Chef::DSL::Resources.remove_resource_dsl)
62
64
  # Remove from DescendantsTracker.
63
65
  Chef::Mixin::DescendantsTracker.direct_descendants(klass.superclass).delete(klass)
64
66
  # Remove from the priority and handler maps.
@@ -17,5 +17,5 @@
17
17
 
18
18
  module Halite
19
19
  # Halite version.
20
- VERSION = '1.0.7'
20
+ VERSION = '1.0.8'
21
21
  end
@@ -57,6 +57,7 @@ describe Halite::SpecHelper do
57
57
  resource(:halite_test)
58
58
  it { is_expected.to be_a(Class) }
59
59
  it { is_expected.to be < Chef::Resource }
60
+ its(:resource_name) { is_expected.to eq :halite_test } if defined?(Chef::Resource.resource_name)
60
61
  it { expect(subject.new(nil, nil).resource_name).to eq(:halite_test) }
61
62
  it { expect(subject.new(nil, nil).action).to eq(:run) }
62
63
  it { expect(subject.new(nil, nil).allowed_actions).to eq([:nothing, :run]) }
@@ -77,6 +78,8 @@ describe Halite::SpecHelper do
77
78
  it { is_expected.to be_a(Class) }
78
79
  it { is_expected.to be < Chef::Resource }
79
80
  it { is_expected.to be < Chef::Resource::File }
81
+ its(:resource_name) { is_expected.to eq :halite_test } if defined?(Chef::Resource.resource_name)
82
+ it { expect(subject.new(nil, nil).resource_name).to eq(:halite_test) }
80
83
  end # /context with a parent
81
84
 
82
85
  context 'with a helper-defined parent' do
@@ -85,6 +88,8 @@ describe Halite::SpecHelper do
85
88
  it { is_expected.to be_a(Class) }
86
89
  it { is_expected.to be < Chef::Resource }
87
90
  it { is_expected.to be < Chef::Resource::HaliteParent }
91
+ its(:resource_name) { is_expected.to eq :halite_test } if defined?(Chef::Resource.resource_name)
92
+ it { expect(subject.new(nil, nil).resource_name).to eq(:halite_test) }
88
93
  end # /context with a helper-defined parent
89
94
 
90
95
  context 'with a helper-defined parent in an enclosing context' do
@@ -142,6 +147,21 @@ describe Halite::SpecHelper do
142
147
  it { is_expected.to run_halite_test('test') }
143
148
  it { is_expected.to_not run_ruby_block('inner') }
144
149
  end # /context with step_into:false
150
+
151
+ describe 'with magic helpers' do
152
+ resource(:halite_test)
153
+
154
+ context 'on the class' do
155
+ its(:example_group) { is_expected.to be_truthy }
156
+ its(:described_class) { is_expected.to eq Halite::SpecHelper }
157
+ end # /context on the class
158
+
159
+ context 'on the instance' do
160
+ subject { super().new(nil, nil) }
161
+ its(:example_group) { is_expected.to be_truthy }
162
+ its(:described_class) { is_expected.to eq Halite::SpecHelper }
163
+ end # /context on the instance
164
+ end # /describe with magic helpers
145
165
  end # /describe #resource
146
166
 
147
167
  describe '#provider' do
@@ -153,6 +173,21 @@ describe Halite::SpecHelper do
153
173
  it { is_expected.to be < Chef::Provider }
154
174
  its(:instance_methods) { are_expected.to include(:action_run) }
155
175
  end # /context with defaults
176
+
177
+ context 'with magic helpers' do
178
+ provider(:halite_test)
179
+
180
+ context 'on the class' do
181
+ its(:example_group) { is_expected.to be_truthy }
182
+ its(:described_class) { is_expected.to eq Halite::SpecHelper }
183
+ end # /context on the class
184
+
185
+ context 'on the instance' do
186
+ subject { super().new(nil, nil) }
187
+ its(:example_group) { is_expected.to be_truthy }
188
+ its(:described_class) { is_expected.to eq Halite::SpecHelper }
189
+ end # /context on the instance
190
+ end # /describe with magic helpers
156
191
  end # /describe #provider
157
192
 
158
193
  describe '#step_into' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
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-17 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef