diff options
author | Bruce Williams <bruce@codefluency.com> | 2010-03-18 02:12:52 -0700 |
---|---|---|
committer | Bruce Williams <bruce@codefluency.com> | 2010-03-18 02:12:52 -0700 |
commit | 3439ff1939e1b547ac732fd5095b2d362296a0af (patch) | |
tree | a7b9e5d1ec4f49b11ad36e2b6dad86bf6e8078e0 | |
parent | 94800be9501c9831c6b9317f52468d24c76d57b9 (diff) | |
download | puppet-vcsrepo-3439ff1939e1b547ac732fd5095b2d362296a0af.tar.gz puppet-vcsrepo-3439ff1939e1b547ac732fd5095b2d362296a0af.tar.bz2 |
Cleanup ProviderExampleGroup
-rw-r--r-- | spec/support/provider_example_group.rb | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/spec/support/provider_example_group.rb b/spec/support/provider_example_group.rb index 626372d..2a8865f 100644 --- a/spec/support/provider_example_group.rb +++ b/spec/support/provider_example_group.rb @@ -1,7 +1,9 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup + # Allow access to the current resource attr_reader :resource - + + # Build up the values for the resource in this scope before :each do resource_hash = example_group_hierarchy.inject({}) do |memo, klass| memo.merge(klass.options[:resource] || {}) @@ -9,42 +11,69 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup full_hash = resource_hash.merge(:provider => described_class.name) @resource = described_class.resource_type.new(full_hash) end - + + # Build the provider subject { described_class.new(@resource) } + + # Allow access to it via +provider+ alias :provider :subject - class << self + # Generate a context for a provider operating on a resource with: + # + # call-seq: + # + # # A parameter/property set (when the value isn't important) + # resource_with :source do + # # ... + # end + # + # # A parameter/property set to a specific value + # resource_with :source => 'a-specific-value' do + # # ... + # end + # + # Note: Choose one or the other (mixing will create two separate contexts) + # + def self.resource_with(*params, &block) + params_with_values = params.last.is_a?(Hash) ? params.pop : {} + build_value_context(params_with_values, &block) + build_existence_context(*params, &block) + end - def field(field, &block) - ResourceField.new(self, field, &block) + def self.build_existence_context(*params, &block) #:nodoc: + unless params.empty? + text = params.join(', ') + placeholders = params.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') } + context("and with a #{text}", {:resource => placeholders}, &block) end - - # call-seq: - # - # given(:ensure) - # given(:ensure => :present) - def resource_with(*args, &block) - options = args.last.is_a?(Hash) ? args.pop : {} - if args.empty? - text = options.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ') - context("and with #{text}", {:resource => options}, &block) - else - text = args.join(', ') - placeholders = args.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') } - context("and with a #{text}", {:resource => placeholders}, &block) - end + end + + def self.build_value_context(params = {}, &block) #:nodoc: + unless params.empty? + text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ') + context("and with #{text}", {:resource => params}, &block) end + end + - def resource_without(field, &block) - context("and without a #{field}", &block) - end - + # Generate a context for a provider operating on a resource without + # a given parameter/property. + # + # call-seq: + # + # resource_without :source do + # # ... + # end + # + def self.resource_without(field, &block) + context("and without a #{field}", &block) end end Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup) +# Outside wrapper to lookup a provider and start the spec using ProviderExampleGroup def describe_provider(type_name, provider_name, options = {}, &block) provider_class = Puppet::Type.type(type_name).provider(provider_name) describe(provider_class, options.merge(:type => :provider), &block) |