diff options
Diffstat (limited to 'spec/support/provider_example_group.rb')
-rw-r--r-- | spec/support/provider_example_group.rb | 51 |
1 files changed, 51 insertions, 0 deletions
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 |