From 94800be9501c9831c6b9317f52468d24c76d57b9 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Thu, 18 Mar 2010 01:52:34 -0700 Subject: Move support file --- spec/support/provider_example_group.rb | 51 ++++++++++++++++++++++++++++++++++ spec/support/resource_helpers.rb | 51 ---------------------------------- 2 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 spec/support/provider_example_group.rb delete mode 100644 spec/support/resource_helpers.rb (limited to 'spec/support') diff --git a/spec/support/provider_example_group.rb b/spec/support/provider_example_group.rb new file mode 100644 index 0000000..626372d --- /dev/null +++ b/spec/support/provider_example_group.rb @@ -0,0 +1,51 @@ +class ProviderExampleGroup < Spec::Example::ExampleGroup + + attr_reader :resource + + 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 + + subject { described_class.new(@resource) } + alias :provider :subject + + class << self + + def field(field, &block) + ResourceField.new(self, field, &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 resource_without(field, &block) + context("and without a #{field}", &block) + end + + end + +end + +Spec::Example::ExampleGroupFactory.register(:provider, 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 diff --git a/spec/support/resource_helpers.rb b/spec/support/resource_helpers.rb deleted file mode 100644 index a4bc74e..0000000 --- a/spec/support/resource_helpers.rb +++ /dev/null @@ -1,51 +0,0 @@ -class ProviderExampleGroup < Spec::Example::ExampleGroup - - attr_reader :resource - - 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 - - subject { described_class.new(@resource) } - alias :provider :subject - - class << self - - def field(field, &block) - ResourceField.new(self, field, &block) - end - - # call-seq: - # - # given(:ensure) - # given(:ensure => :present) - def context_with_resource(*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 context_without_resource(field, &block) - context("and without a #{field}", &block) - end - - end - -end - -Spec::Example::ExampleGroupFactory.register(:provider, 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