From 736c094145ff6f86d2bfdc8cecf32da8180d95fe Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Wed, 17 Mar 2010 23:54:02 -0700 Subject: Further condense provider example group API, update Bazaar provider spec to use it. --- spec/support/resource_helpers.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/support') diff --git a/spec/support/resource_helpers.rb b/spec/support/resource_helpers.rb index 8327ec0..00bf259 100644 --- a/spec/support/resource_helpers.rb +++ b/spec/support/resource_helpers.rb @@ -17,6 +17,34 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup resource.value(name) end + class << self + + def field(field, &block) + ResourceField.new(self, field, &block) + end + + # call-seq: + # + # given(:ensure) + # given(:ensure => :present) + def context_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 context_without(field, &block) + context("and without a #{field}", &block) + end + + end + end Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup) -- cgit v1.2.3