From aeb3ea63ec561440c02f9d4c4d4c0ac3a1d096c9 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 15:59:44 -0400 Subject: Overhaul the spec tests to work in rspec2. This work gets rid of the provider_example_group and reworks everything to work properly against rspec2. I don't know if I'd consider the style "better" but it works. --- spec/support/provider_example_group.rb | 80 ---------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 spec/support/provider_example_group.rb (limited to 'spec/support') diff --git a/spec/support/provider_example_group.rb b/spec/support/provider_example_group.rb deleted file mode 100644 index 1431f78..0000000 --- a/spec/support/provider_example_group.rb +++ /dev/null @@ -1,80 +0,0 @@ -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] || {}) - end - 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 - - # 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 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 - 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 - - - # 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) -end -- cgit v1.2.3