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/bzr_spec.rb | 73 +++++++++++++++++---------- 1 file changed, 46 insertions(+), 27 deletions(-) (limited to 'spec/unit/puppet/provider/vcsrepo/bzr_spec.rb') diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index c0231e9..488ddc0 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -1,24 +1,41 @@ require 'spec_helper' -describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :bzr, + :revision => '2634', + :source => 'lp:do', + :path => '/tmp/test', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr') + end describe 'creating' do - resource_with :source do - resource_with :revision do - it "should execute 'bzr clone -r' with the revision" do - provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) - provider.create - end + context 'with defaults' do + it "should execute 'bzr clone -r' with the revision" do + provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) + provider.create end - resource_without :revision do - it "should just execute 'bzr clone' without a revision" do - provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) - provider.create - end + end + + context 'without revision' do + it "should just execute 'bzr clone' without a revision" do + resource.delete(:revision) + provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) + provider.create end end - resource_without :source do + + context 'without source' do it "should execute 'bzr init'" do + resource.delete(:source) provider.expects(:bzr).with('init', resource.value(:path)) provider.create end @@ -27,14 +44,13 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe 'destroying' do it "it should remove the directory" do - expects_rm_rf provider.destroy end end describe "checking existence" do it "should check for the directory" do - expects_directory?(true, File.join(resource.value(:path), '.bzr')) + File.expects(:directory?).with(File.join(resource.value(:path), '.bzr')).returns(true) provider.exists? end end @@ -42,46 +58,49 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe "checking the revision property" do before do expects_chdir - provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info)) + provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt'))) @current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' end - context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do + + context "when given a non-revid as the resource revision" do context "when its revid is not different than the current revid" do - before do - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") - end it "should return the ref" do + resource[:revision] = '2634' + provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") provider.revision.should == resource.value(:revision) end end - context "when its revid is different than the current revid", :resource => {:revision => '2636'} do + context "when its revid is different than the current revid" do it "should return the current revid" do + resource[:revision] = '2636' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") provider.revision.should == @current_revid end end end + context "when given a revid as the resource revision" do - context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do - before do - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") - end + context "when it is the same as the current revid" do it "should return it" do + resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' + provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") provider.revision.should == resource.value(:revision) end end - context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do + context "when it is not the same as the current revid" do it "should return the current revid" do + resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") provider.revision.should == @current_revid end end + end end describe "setting the revision property" do it "should use 'bzr update -r' with the revision" do - expects_chdir + Dir.expects(:chdir).with('/tmp/test').at_least_once.yields provider.expects(:bzr).with('update', '-r', 'somerev') provider.revision = 'somerev' end -- cgit v1.2.3 From 1df5570580c1d429a8fed25033a19333fcaffbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 29 Sep 2014 19:19:21 +0200 Subject: Convert specs to RSpec 2.99.2 syntax with Transpec This conversion is done by Transpec 2.3.7 with the following command: transpec * 22 conversions from: it { should ... } to: it { is_expected.to ... } * 19 conversions from: obj.should to: expect(obj).to * 15 conversions from: == expected to: eq(expected) * 5 conversions from: it { should_not ... } to: it { is_expected.not_to ... } * 2 conversions from: its(:attr) { } to: describe '#attr' do subject { super().attr }; it { } end * 2 conversions from: obj.should_not to: expect(obj).not_to * 2 conversions from: proc { }.should to: expect { }.to * 1 conversion from: be_false to: be_falsey * 1 conversion from: be_true to: be_truthy For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/unit/puppet/provider/vcsrepo/bzr_spec.rb') diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index 488ddc0..b5e2f73 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -67,14 +67,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do it "should return the ref" do resource[:revision] = '2634' provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end context "when its revid is different than the current revid" do it "should return the current revid" do resource[:revision] = '2636' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") - provider.revision.should == @current_revid + expect(provider.revision).to eq(@current_revid) end end end @@ -84,14 +84,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do it "should return it" do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end context "when it is not the same as the current revid" do it "should return the current revid" do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") - provider.revision.should == @current_revid + expect(provider.revision).to eq(@current_revid) end end -- cgit v1.2.3