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/unit/puppet/provider/vcsrepo/hg_spec.rb | 52 +++++++++++++++++++--------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'spec/unit/puppet/provider/vcsrepo/hg_spec.rb') diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index f17aa2f..7fd5348 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -1,24 +1,38 @@ require 'spec_helper' -describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:hg) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :hg, + :path => '/tmp/vcsrepo', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg') + end describe 'creating' do - resource_with :source do - resource_with :revision do - it "should execute 'hg clone -u' with the revision" do - provider.expects(:hg).with('clone', '-u', - resource.value(:revision), - resource.value(:source), - resource.value(:path)) - provider.create - end + context 'with source and revision' do + it "should execute 'hg clone -u' with the revision" do + resource[:source] = 'something' + resource[:revision] = '1' + provider.expects(:hg).with('clone', '-u', + resource.value(:revision), + resource.value(:source), + resource.value(:path)) + provider.create end + end - resource_without :revision do - it "should just execute 'hg clone' without a revision" do - provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) - provider.create - end + context 'without revision' do + it "should just execute 'hg clone' without a revision" do + resource[:source] = 'something' + provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) + provider.create end end @@ -55,14 +69,16 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) end - context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do + context "when its SHA is not different than the current SHA" do it "should return the ref" do + resource[:revision] = '0.6' provider.revision.should == '0.6' end end - context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do + context "when its SHA is different than the current SHA" do it "should return the current SHA" do + resource[:revision] = '0.5.3' provider.revision.should == '34e6012c783a' end end @@ -74,6 +90,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do it "should return it" do + resource[:revision] = '34e6012c783a' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.revision.should == resource.value(:revision) end @@ -81,6 +98,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do it "should return the current SHA" do + resource[:revision] = 'not-the-same' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.revision.should == '34e6012c783a' end -- cgit v1.2.3