From f373a8b78935b0ee1005df0ead235d76a79178c5 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Thu, 18 Oct 2012 22:01:46 -0700 Subject: Get the specs running under bundler. --- spec/spec_helper.rb | 1 + spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 95e5d6e..3bac650 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require 'pathname' dir = Pathname.new(__FILE__).parent $LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') +require 'test/unit' require 'mocha' require 'puppet' gem 'rspec', '>= 1.2.9' diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index f073b8e..c50574a 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -1,4 +1,4 @@ -require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end } +require 'spec_helper' describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index cc195eb..7c26952 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -1,4 +1,4 @@ -require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end } +require 'spec_helper' describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 4a1085a..1ff2a2b 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -1,4 +1,4 @@ -require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end } +require 'spec_helper' describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 6f32d44..318ddb0 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -1,4 +1,4 @@ -require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end } +require 'spec_helper' describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index db4a4c7..042554c 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -1,4 +1,4 @@ -require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end } +require 'spec_helper' describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do -- cgit v1.2.3 From 86594324171caf4dc96453ed3a7b56444e48b6d1 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Thu, 18 Oct 2012 23:23:05 -0700 Subject: Update tests to match current code. --- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 15 +++++---- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 45 ++++++++++++++++----------- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 10 +++--- 3 files changed, 38 insertions(+), 32 deletions(-) (limited to 'spec') diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index 7c26952..c16c7ea 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -6,10 +6,9 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do resource_with :revision do it "should execute 'cvs checkout' and 'cvs update -r'" do - expects_chdir + provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar') expects_chdir(File.dirname(resource.value(:path))) - provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) - provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.') + #provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.') provider.create end end @@ -67,7 +66,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do context "when CVS/Tag exists" do before do - @tag = 'HEAD' + @tag = 'TAG' File.expects(:exist?).with(@tag_file).returns(true) end it "should read CVS/Tag" do @@ -80,8 +79,8 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do before do File.expects(:exist?).with(@tag_file).returns(false) end - it "assumes MAIN" do - provider.revision.should == 'MAIN' + it "assumes HEAD" do + provider.revision.should == 'HEAD' end end end @@ -91,9 +90,9 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do @tag = 'SOMETAG' end - it "should use 'cvs update -r'" do + it "should use 'cvs update -dr'" do expects_chdir - provider.expects('cvs').with('update', '-r', @tag, '.') + provider.expects('cvs').with('update', '-dr', @tag, '.') provider.revision = @tag end end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 1ff2a2b..240b2b8 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -9,9 +9,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do it "should execute 'git clone' and 'git checkout -b'" do provider.expects('git').with('clone', resource.value(:source), resource.value(:path)) expects_chdir - provider.expects(:remote_revision_branch?).returns(true) - provider.expects(:git).with('checkout', '-b', resource.value(:revision), '--track', "origin/#{resource.value(:revision)}") provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end end @@ -19,9 +19,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do it "should execute 'git clone' and 'git reset --hard'" do provider.expects('git').with('clone', resource.value(:source), resource.value(:path)) expects_chdir - provider.expects(:remote_revision_branch?).returns(false) - provider.expects('git').with('reset', '--hard', resource.value(:revision)) provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end end @@ -74,8 +74,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when the path is not a repository" do it "should raise an exception" do - expects_directory?(true) - provider.expects(:bare_exists?).returns(false) + provider.expects(:path_exists?).returns(true) proc { provider.create }.should raise_error(Puppet::Error) end end @@ -104,7 +103,6 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when the path is not a repository" do it "should raise an exception" do expects_directory?(true) - provider.expects(:working_copy_exists?).returns(false) proc { provider.create }.should raise_error(Puppet::Error) end end @@ -129,14 +127,20 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when its SHA is not different than the current SHA" do it "should return the ref" do + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + provider.expects(:git).with('tag', '-l').returns("Hello") provider.revision.should == resource.value(:revision) end end context "when its SHA is different than the current SHA" do it "should return the current SHA" do + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha') + provider.expects(:git).with('tag', '-l').returns("Hello") provider.revision.should == 'currentsha' end end @@ -146,35 +150,37 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "setting the revision property" do before do expects_chdir - provider.expects(:git).with('fetch', 'origin') end context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do it "should use 'git fetch' and 'git reset'" do - provider.expects(:local_revision_branch?).returns(true) - provider.expects(:git).with('checkout', resource.value(:revision)) - provider.expects(:git).with('pull', 'origin') provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end end context "when it's a remote branch", :resource => {:revision => 'only/remote'} do it "should use 'git fetch' and 'git reset'" do - provider.expects(:local_revision_branch?).returns(false) - provider.expects(:remote_revision_branch?).returns(true) - provider.expects(:git).with('checkout', - '-b', resource.value(:revision), - '--track', "origin/#{resource.value(:revision)}") provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end end context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do it "should use 'git fetch' and 'git reset'" do - provider.expects(:local_revision_branch?).returns(false) - provider.expects(:remote_revision_branch?).returns(false) - provider.expects(:git).with('reset', '--hard', resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) provider.expects(:git).with('submodule', 'init') provider.expects(:git).with('submodule', 'update') + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) + provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'init') + provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update') provider.revision = resource.value(:revision) end end @@ -183,6 +189,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "updating references" do it "should use 'git fetch --tags'" do expects_chdir + provider.expects(:git).with('fetch', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin') provider.update_references end diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 042554c..5c27818 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -6,7 +6,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do resource_with :source do resource_with :revision do it "should execute 'svn checkout' with a revision" do - provider.expects(:svn).with('checkout', '-r', + provider.expects(:svn).with('--non-interactive', 'checkout', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) @@ -15,7 +15,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do end resource_without :revision do it "should just execute 'svn checkout' without a revision" do - provider.expects(:svn).with('checkout', + provider.expects(:svn).with('--non-interactive', 'checkout', resource.value(:source), resource.value(:path)) provider.create @@ -56,11 +56,11 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do describe "checking the revision property" do before do - provider.expects('svn').with('info').returns(fixture(:svn_info)) + provider.expects('svn').with('--non-interactive', 'info').returns(fixture(:svn_info)) end it "should use 'svn info'" do expects_chdir - provider.revision.should == '4' + provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision' end end @@ -70,7 +70,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do end it "should use 'svn update'" do expects_chdir - provider.expects('svn').with('update', '-r', @revision) + provider.expects('svn').with('--non-interactive', 'update', '-r', @revision) provider.revision = @revision end end -- cgit v1.2.3 From 5402f4f1dd4b315f14afa671e3c2c236ac9f53ce Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Thu, 18 Oct 2012 23:31:29 -0700 Subject: Remove excess whitespace. --- lib/puppet/provider/vcsrepo/bzr.rb | 2 +- lib/puppet/provider/vcsrepo/cvs.rb | 12 ++++----- lib/puppet/provider/vcsrepo/svn.rb | 4 +-- lib/puppet/type/vcsrepo.rb | 4 +-- spec/support/filesystem_helpers.rb | 2 +- spec/support/fixture_helpers.rb | 2 +- spec/support/provider_example_group.rb | 6 ++--- spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 22 ++++++++-------- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 36 +++++++++++++-------------- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 22 ++++++++-------- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 6 ++--- 12 files changed, 60 insertions(+), 60 deletions(-) (limited to 'spec') diff --git a/lib/puppet/provider/vcsrepo/bzr.rb b/lib/puppet/provider/vcsrepo/bzr.rb index 8b10cab..6169929 100644 --- a/lib/puppet/provider/vcsrepo/bzr.rb +++ b/lib/puppet/provider/vcsrepo/bzr.rb @@ -25,7 +25,7 @@ Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) def destroy FileUtils.rm_rf(@resource.value(:path)) end - + def revision at_path do current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1] diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb index 21485d3..467e2f9 100644 --- a/lib/puppet/provider/vcsrepo/cvs.rb +++ b/lib/puppet/provider/vcsrepo/cvs.rb @@ -5,7 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) optional_commands :cvs => 'cvs' has_features :gzip_compression, :reference_tracking, :modules - + def create if !@resource.value(:source) create_repository(@resource.value(:path)) @@ -27,12 +27,12 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) def working_copy_exists? File.directory?(File.join(@resource.value(:path), 'CVS')) end - + def destroy FileUtils.rm_rf(@resource.value(:path)) end - def latest? + def latest? debug "Checking for updates because 'ensure => latest'" at_path do # We cannot use -P to prune empty dirs, otherwise @@ -43,10 +43,10 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) return is_current end end - + def latest # CVS does not have a conecpt like commit-IDs or change - # sets, so we can only have the current branch name (or the + # sets, so we can only have the current branch name (or the # requested one, if that differs) as the "latest" revision. should = @resource.value(:revision) current = self.revision @@ -116,5 +116,5 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) set_ownership end end - + end diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb index bf21813..b2a8880 100644 --- a/lib/puppet/provider/vcsrepo/svn.rb +++ b/lib/puppet/provider/vcsrepo/svn.rb @@ -40,7 +40,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) end end end - + def buildargs args = ['--non-interactive'] if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password) @@ -57,7 +57,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1] end end - + def revision args = buildargs.push('info') at_path do diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index 352f439..4b53235 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -21,7 +21,7 @@ Puppet::Type.newtype(:vcsrepo) do feature :ssh_identity, "The provider supports a configurable SSH identity file" - + feature :user, "The provider can run as a different user" @@ -167,7 +167,7 @@ Puppet::Type.newtype(:vcsrepo) do newparam :identity, :required_features => [:ssh_identity] do desc "SSH identity file" end - + newparam :module, :required_features => [:modules] do desc "The repository module to manage" end diff --git a/spec/support/filesystem_helpers.rb b/spec/support/filesystem_helpers.rb index 08345b4..15e2ca7 100644 --- a/spec/support/filesystem_helpers.rb +++ b/spec/support/filesystem_helpers.rb @@ -3,7 +3,7 @@ module FilesystemHelpers def expects_chdir(path = resource.value(:path)) Dir.expects(:chdir).with(path).at_least_once.yields end - + def expects_mkdir(path = resource.value(:path)) Dir.expects(:mkdir).with(path).at_least_once end diff --git a/spec/support/fixture_helpers.rb b/spec/support/fixture_helpers.rb index 7b7b20a..8a0e0a0 100644 --- a/spec/support/fixture_helpers.rb +++ b/spec/support/fixture_helpers.rb @@ -3,5 +3,5 @@ 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_example_group.rb b/spec/support/provider_example_group.rb index 2a8865f..1431f78 100644 --- a/spec/support/provider_example_group.rb +++ b/spec/support/provider_example_group.rb @@ -14,7 +14,7 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup # Build the provider subject { described_class.new(@resource) } - + # Allow access to it via +provider+ alias :provider :subject @@ -47,14 +47,14 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup context("and with a #{text}", {:resource => placeholders}, &block) end end - + def self.build_value_context(params = {}, &block) #:nodoc: unless params.empty? text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ') context("and with #{text}", {:resource => params}, &block) end end - + # Generate a context for a provider operating on a resource without # a given parameter/property. diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index c50574a..cccbaa6 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -78,7 +78,7 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do end end end - + describe "setting the revision property" do it "should use 'bzr update -r' with the revision" do revision = 'somerev' diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index c16c7ea..4c15757 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -10,24 +10,24 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do expects_chdir(File.dirname(resource.value(:path))) #provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.') provider.create - end + end end - + resource_without :revision do it "should just execute 'cvs checkout' without a revision" do provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) provider.create - end + end end - + context "with a compression", :resource => {:compression => '3'} do it "should just execute 'cvs checkout' without a revision" do provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) provider.create - end + end end end - + context "when a source is not given" do it "should execute 'cvs init'" do provider.expects(:cvs).with('-d', resource.value(:path), 'init') @@ -50,7 +50,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do provider.exists? end end - + resource_without :source do it "should check for the CVSROOT directory" do File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')) @@ -63,7 +63,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do before do @tag_file = File.join(resource.value(:path), 'CVS', 'Tag') end - + context "when CVS/Tag exists" do before do @tag = 'TAG' @@ -74,7 +74,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do provider.revision.should == @tag end end - + context "when CVS/Tag does not exist" do before do File.expects(:exist?).with(@tag_file).returns(false) @@ -84,12 +84,12 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do end end end - + describe "when setting the revision property" do before do @tag = 'SOMETAG' end - + it "should use 'cvs update -dr'" do expects_chdir provider.expects('cvs').with('update', '-dr', @tag, '.') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 240b2b8..7d5d327 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -24,7 +24,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end - end + end resource_without :revision do it "should execute 'git clone' and submodule commands" do provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) @@ -33,7 +33,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end end - + resource_with :ensure => :bare do resource_with :revision do it "should just execute 'git clone --bare'" do @@ -41,7 +41,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.create end end - + resource_without :revision do it "should just execute 'git clone --bare'" do provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) @@ -50,7 +50,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end end - + context "when a source is not given" do resource_with :ensure => :present do context "when the path does not exist" do @@ -63,7 +63,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.create end end - + context "when the path is a bare repository" do it "should convert it to a working copy" do provider.expects(:bare_exists?).returns(true) @@ -71,7 +71,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.create end end - + context "when the path is not a repository" do it "should raise an exception" do provider.expects(:path_exists?).returns(true) @@ -79,7 +79,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end end - + resource_with :ensure => :bare do context "when the path does not exist" do it "should execute 'git init --bare'" do @@ -91,7 +91,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.create end end - + context "when the path is a working copy repository" do it "should convert it to a bare repository" do provider.expects(:working_copy_exists?).returns(true) @@ -99,7 +99,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.create end end - + context "when the path is not a repository" do it "should raise an exception" do expects_directory?(true) @@ -110,21 +110,21 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end - + context 'destroying' do it "it should remove the directory" do expects_rm_rf provider.destroy end end - + context "checking the revision property" do resource_with :revision do before do expects_chdir provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha') end - + context "when its SHA is not different than the current SHA" do it "should return the ref" do provider.expects(:git).with('fetch', 'origin') # FIXME @@ -134,7 +134,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.revision.should == resource.value(:revision) end end - + context "when its SHA is different than the current SHA" do it "should return the current SHA" do provider.expects(:git).with('fetch', 'origin') # FIXME @@ -146,7 +146,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end end - + context "setting the revision property" do before do expects_chdir @@ -183,9 +183,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update') provider.revision = resource.value(:revision) end - end + end end - + context "updating references" do it "should use 'git fetch --tags'" do expects_chdir @@ -223,7 +223,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.should_not be_remote_branch_revision end end - end + end end - + end diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 318ddb0..948bfe0 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -11,17 +11,17 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do resource.value(:source), resource.value(:path)) provider.create - end + 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 + end end end - + context "when a source is not given" do it "should execute 'hg init'" do provider.expects(:hg).with('init', resource.value(:path)) @@ -48,37 +48,37 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do before do expects_chdir end - + context "when given a non-SHA as the resource revision" do before do provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) 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 it "should return the ref" do provider.revision.should == '0.6' end end - + context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do it "should return the current SHA" do provider.revision.should == '34e6012c783a' - end + end end end context "when given a SHA as the resource revision" do before do provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) end - + context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do it "should return it" do provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.revision.should == resource.value(:revision) end end - + context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do it "should return the current SHA" do provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) @@ -87,7 +87,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do end end end - + describe "setting the revision property" do before do @revision = '6aa99e9b3ab1' diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 5c27818..d360433 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -11,7 +11,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do resource.value(:source), resource.value(:path)) provider.create - end + end end resource_without :revision do it "should just execute 'svn checkout' without a revision" do @@ -19,7 +19,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do resource.value(:source), resource.value(:path)) provider.create - end + end end end resource_without :source do @@ -63,7 +63,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision' end end - + describe "setting the revision property" do before do @revision = '30' -- cgit v1.2.3 From 821c66fe76056784f84376e5beb4d2de629998ed Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Fri, 19 Oct 2012 00:26:39 -0700 Subject: Use symbols consistently with provider.expects() --- spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 2 +- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 4 ++-- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 6 +++--- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'spec') diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index cccbaa6..e1804de 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -82,7 +82,7 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe "setting the revision property" do it "should use 'bzr update -r' with the revision" do revision = 'somerev' - provider.expects('bzr').with('update', '-r', revision, resource.value(:path)) + provider.expects(:bzr).with('update', '-r', revision, resource.value(:path)) provider.revision = revision end end diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index 4c15757..aad54cc 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -92,7 +92,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do it "should use 'cvs update -dr'" do expects_chdir - provider.expects('cvs').with('update', '-dr', @tag, '.') + provider.expects(:cvs).with('update', '-dr', @tag, '.') provider.revision = @tag end end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 7d5d327..83dbff2 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -7,7 +7,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do resource_with :ensure => :present do context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do it "should execute 'git clone' and 'git checkout -b'" do - provider.expects('git').with('clone', resource.value(:source), resource.value(:path)) + provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) expects_chdir provider.expects(:update_submodules) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) @@ -17,7 +17,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do it "should execute 'git clone' and 'git reset --hard'" do - provider.expects('git').with('clone', resource.value(:source), resource.value(:path)) + provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) expects_chdir provider.expects(:update_submodules) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 948bfe0..f17aa2f 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -94,9 +94,9 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do end it "should use 'hg update ---clean -r'" do expects_chdir - provider.expects('hg').with('pull') - provider.expects('hg').with('merge') - provider.expects('hg').with('update', '--clean', '-r', @revision) + provider.expects(:hg).with('pull') + provider.expects(:hg).with('merge') + provider.expects(:hg).with('update', '--clean', '-r', @revision) provider.revision = @revision end end diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index d360433..75d58f9 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -56,7 +56,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do describe "checking the revision property" do before do - provider.expects('svn').with('--non-interactive', 'info').returns(fixture(:svn_info)) + provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info)) end it "should use 'svn info'" do expects_chdir @@ -70,7 +70,7 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do end it "should use 'svn update'" do expects_chdir - provider.expects('svn').with('--non-interactive', 'update', '-r', @revision) + provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision) provider.revision = @revision end end -- cgit v1.2.3 From 72df8ecb489c13a0bf7bdb78455e6d523404dd8b Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Fri, 19 Oct 2012 01:25:19 -0700 Subject: Dummy provider raises an exception if it is used. Tests to prove it. --- lib/puppet/provider/vcsrepo/dummy.rb | 5 +++++ spec/unit/puppet/provider/vcsrepo/dummy_spec.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 spec/unit/puppet/provider/vcsrepo/dummy_spec.rb (limited to 'spec') diff --git a/lib/puppet/provider/vcsrepo/dummy.rb b/lib/puppet/provider/vcsrepo/dummy.rb index f76e090..f7b4e54 100644 --- a/lib/puppet/provider/vcsrepo/dummy.rb +++ b/lib/puppet/provider/vcsrepo/dummy.rb @@ -4,4 +4,9 @@ Puppet::Type.type(:vcsrepo).provide(:dummy, :parent => Puppet::Provider::Vcsrepo desc "Dummy default provider" defaultfor :vcsrepo => :dummy + + def working_copy_exists? + providers = @resource.class.providers.map{|x| x.to_s}.sort.reject{|x| x == "dummy"}.join(", ") rescue "none" + raise("vcsrepo resource must have a provider, available: #{providers}") + end end diff --git a/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb b/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb new file mode 100644 index 0000000..a945888 --- /dev/null +++ b/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do + + context 'dummy' do + resource_with :source do + resource_with :ensure => :present do + context "with nothing doing", :resource => {:revision => 'foo'} do + it "should raise an exception" do + proc { provider.working_copy_exists? }.should raise_error(RuntimeError) + end + end + end + end + end + +end -- cgit v1.2.3