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 From 2ff03cff1795d3e43c922f7bceb235ce69175013 Mon Sep 17 00:00:00 2001 From: Stuart Whelan Date: Sat, 21 Jun 2014 17:26:14 +1200 Subject: Added support for basic authentication to hg provider Updated unit tests Updated hg readme and added examples --- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (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 7fd5348..6b21c1c 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -42,6 +42,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do provider.create end end + + context "when basic auth is used" do + it "should execute 'hg clone'" do + resource[:source] = 'something' + resource[:basic_auth_username] = 'user' + resource[:basic_auth_password] = 'pass' + provider.expects(:hg).with('clone', + resource.value(:source), + resource.value(:path), + "--config","\"auth.x.prefix=" + resource.value(:source) + "\"", + "--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"", + "--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"", + "--config","\"auth.x.schemes=http https" + "\"") + provider.create + end + end end describe 'destroying' do -- 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/hg_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 6b21c1c..65d820d 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -88,14 +88,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) 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' + expect(provider.revision).to eq('0.6') end end 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' + expect(provider.revision).to eq('34e6012c783a') end end end @@ -108,7 +108,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do it "should return it" do resource[:revision] = '34e6012c783a' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end @@ -116,7 +116,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) 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' + expect(provider.revision).to eq('34e6012c783a') end end end -- cgit v1.2.3