diff options
author | Bruce Williams <bruce@codefluency.com> | 2010-03-17 20:23:22 -0700 |
---|---|---|
committer | Bruce Williams <bruce@codefluency.com> | 2010-03-17 20:23:22 -0700 |
commit | 532cfbb18195ba759574e91dc6bd360978045e75 (patch) | |
tree | d1dacdf10ad4106671ceb01ae2af7130c247da5d /spec/support | |
parent | 4b8e7074e62900ed796cc05bb67a7561f40f899a (diff) |
Build ProviderExampleGroup for refactored provider tests
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/fixture_helpers.rb | 7 | ||||
-rw-r--r-- | spec/support/provider_subject.rb | 7 | ||||
-rw-r--r-- | spec/support/resource_helpers.rb | 27 | ||||
-rw-r--r-- | spec/support/vcsrepo_helpers.rb | 12 |
4 files changed, 53 insertions, 0 deletions
diff --git a/spec/support/fixture_helpers.rb b/spec/support/fixture_helpers.rb new file mode 100644 index 0000000..7b7b20a --- /dev/null +++ b/spec/support/fixture_helpers.rb @@ -0,0 +1,7 @@ +module FixtureHelpers + + def fixture(name, ext = '.txt') + File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext)) + end + +end diff --git a/spec/support/provider_subject.rb b/spec/support/provider_subject.rb new file mode 100644 index 0000000..de7ce7c --- /dev/null +++ b/spec/support/provider_subject.rb @@ -0,0 +1,7 @@ +module ProviderSubject + + def provider + subject + end + +end diff --git a/spec/support/resource_helpers.rb b/spec/support/resource_helpers.rb new file mode 100644 index 0000000..8327ec0 --- /dev/null +++ b/spec/support/resource_helpers.rb @@ -0,0 +1,27 @@ +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 + + def _(name) + resource.value(name) + 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/vcsrepo_helpers.rb b/spec/support/vcsrepo_helpers.rb new file mode 100644 index 0000000..e0b9beb --- /dev/null +++ b/spec/support/vcsrepo_helpers.rb @@ -0,0 +1,12 @@ +module VcsrepoHelpers + + def expects_chdir + Dir.expects(:chdir).with(resource.value(:path)).at_least_once.yields + end + + def expects_mkdir + Dir.expects(:mkdir).with(resource.value(:path)).at_least_once + end + + +end |