summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-18 01:02:02 -0700
committerBruce Williams <bruce@codefluency.com>2010-03-18 01:02:02 -0700
commitaf86e9ba814926f9ee236aabc2ca905b5668af70 (patch)
treecc7d51046dbe0421b8f70bc1f1cca006a994fc2c
parentdfb28337ce3c0743ed17ed21f5bab7e1692144bf (diff)
Subversion to use provider example group API for specs
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb2
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/support/provider_subject.rb7
-rw-r--r--spec/support/resource_helpers.rb4
-rw-r--r--spec/support/vcsrepo_helpers.rb11
-rw-r--r--spec/unit/puppet/provider/vcsrepo/bzr_spec.rb4
-rw-r--r--spec/unit/puppet/provider/vcsrepo/cvs_spec.rb2
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb10
-rw-r--r--spec/unit/puppet/provider/vcsrepo/hg_spec.rb11
-rw-r--r--spec/unit/puppet/provider/vcsrepo/svn_spec.rb96
10 files changed, 62 insertions, 89 deletions
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 5fa586d..f712bf5 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -20,7 +20,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
end
def exists?
- File.directory?(@resource.value(:path))
+ File.directory?(File.join(@resource.value(:path), '.svn'))
end
def destroy
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 40b79f1..95e5d6e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
require 'mocha'
require 'puppet'
-gem 'rspec', '=1.2.9'
+gem 'rspec', '>= 1.2.9'
require 'spec/autorun'
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file|
@@ -14,7 +14,7 @@ end
Spec::Runner.configure do |config|
config.mock_with :mocha
config.include(FixtureHelpers)
- config.include(VcsrepoHelpers)
+ config.include(FilesystemHelpers)
end
# We need this because the RAL uses 'should' as a method. This
diff --git a/spec/support/provider_subject.rb b/spec/support/provider_subject.rb
deleted file mode 100644
index de7ce7c..0000000
--- a/spec/support/provider_subject.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module ProviderSubject
-
- def provider
- subject
- end
-
-end
diff --git a/spec/support/resource_helpers.rb b/spec/support/resource_helpers.rb
index 00bf259..a4098b3 100644
--- a/spec/support/resource_helpers.rb
+++ b/spec/support/resource_helpers.rb
@@ -13,10 +13,6 @@ class ProviderExampleGroup < Spec::Example::ExampleGroup
subject { described_class.new(@resource) }
alias :provider :subject
- def _(name)
- resource.value(name)
- end
-
class << self
def field(field, &block)
diff --git a/spec/support/vcsrepo_helpers.rb b/spec/support/vcsrepo_helpers.rb
deleted file mode 100644
index f631db0d..0000000
--- a/spec/support/vcsrepo_helpers.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module VcsrepoHelpers
-
- 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
-
-end
diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb
index 67f9913..d122e60 100644
--- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb
@@ -27,14 +27,14 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do
describe 'destroying' do
it "it should remove the directory" do
- FileUtils.expects(:rm_rf).with(resource.value(:path))
+ expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
- File.expects(:directory?).with(File.join(resource.value(:path), '.bzr'))
+ expects_directory?(true, File.join(resource.value(:path), '.bzr'))
provider.exists?
end
end
diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
index 2860af5..5122e50 100644
--- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
@@ -39,7 +39,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do
describe 'destroying' do
it "it should remove the directory" do
- FileUtils.expects(:rm_rf).with(resource.value(:path))
+ expects_rm_rf
provider.destroy
end
end
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index 2d55451..698687f 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -45,8 +45,8 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
it "should execute 'git init'" do
expects_mkdir
expects_chdir
+ expects_directory?(false)
provider.expects(:bare_exists?).returns(false)
- File.expects(:directory?).with(resource.value(:path)).returns(false)
provider.expects(:git).with('init')
provider.create
end
@@ -62,7 +62,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
- File.expects(:directory?).with(resource.value(:path)).returns(true)
+ expects_directory?(true)
provider.expects(:bare_exists?).returns(false)
proc { provider.create }.should raise_error(Puppet::Error)
end
@@ -74,7 +74,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
it "should execute 'git init --bare'" do
expects_chdir
expects_mkdir
- File.expects(:directory?).with(resource.value(:path)).returns(false)
+ expects_directory?(false)
provider.expects(:working_copy_exists?).returns(false)
provider.expects(:git).with('init', '--bare')
provider.create
@@ -91,7 +91,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
- File.expects(:directory?).with(resource.value(:path)).returns(true)
+ expects_directory?(true)
provider.expects(:working_copy_exists?).returns(false)
proc { provider.create }.should raise_error(Puppet::Error)
end
@@ -101,7 +101,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
context 'destroying' do
it "it should remove the directory" do
- FileUtils.expects(:rm_rf).with(resource.value(:path))
+ expects_rm_rf
provider.destroy
end
end
diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
index a6c8301..a79571a 100644
--- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
@@ -13,6 +13,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
provider.create
end
end
+
context_without :revision do
it "should just execute 'hg clone' without a revision" do
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
@@ -20,6 +21,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
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))
@@ -30,14 +32,14 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
describe 'destroying' do
it "it should remove the directory" do
- FileUtils.expects(:rm_rf).with(resource.value(:path))
+ expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
- File.expects(:directory?).with(File.join(resource.value(:path), '.hg'))
+ expects_directory?(true, File.join(resource.value(:path), '.hg'))
provider.exists?
end
end
@@ -46,16 +48,19 @@ 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'
@@ -66,12 +71,14 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} 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').never
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))
diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
index fc5c37b..fcb7222 100644
--- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
@@ -1,89 +1,77 @@
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
-provider_class = Puppet::Type.type(:vcsrepo).provider(:svn)
+describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do
-describe provider_class do
-
- before :each do
- @resource = stub("resource")
- @provider = provider_class.new(@resource)
- @path = '/tmp/vcsrepo'
- end
-
- describe 'when creating' do
- context "when a source is given" do
- context "and when a revision is given" do
+ describe 'creating' do
+ context_with :source do
+ context_with :revision do
it "should execute 'svn checkout' with a revision" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
- @resource.expects(:value).with(:revision).returns('1234').at_least_once
- @provider.expects(:svn).with('checkout', '-r', '1234', 'svn://example.com/repo', @path)
- @provider.create
+ provider.expects(:svn).with('checkout', '-r',
+ resource.value(:revision),
+ resource.value(:source),
+ resource.value(:path))
+ provider.create
end
end
- context "and when a revision is not given" do
+ context_without :revision do
it "should just execute 'svn checkout' without a revision" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
- @resource.expects(:value).with(:revision).returns(nil).at_least_once
- @provider.expects(:svn).with('checkout','svn://example.com/repo', @path)
- @provider.create
+ provider.expects(:svn).with('checkout',
+ resource.value(:source),
+ resource.value(:path))
+ provider.create
end
end
end
- context "when a source is not given" do
- context "when a fstype is given" do
+ context_without :source do
+ context_with :fstype do
it "should execute 'svnadmin create' with an '--fs-type' option" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:fstype).returns('fsfs').at_least_once
- @resource.expects(:value).with(:source).returns(nil)
- @provider.expects(:svnadmin).with('create', '--fs-type', 'fsfs', @path)
- @provider.create
+ provider.expects(:svnadmin).with('create', '--fs-type',
+ resource.value(:fstype),
+ resource.value(:path))
+ provider.create
end
end
- context "when a fstype is not given" do
+ context_without :fstype do
it "should execute 'svnadmin create' without an '--fs-type' option" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:source).returns(nil)
- @resource.expects(:value).with(:fstype).returns(nil).at_least_once
- @provider.expects(:svnadmin).with('create', @path)
- @provider.create
+ provider.expects(:svnadmin).with('create', resource.value(:path))
+ provider.create
end
end
end
end
- describe 'when destroying' do
+ describe 'destroying' do
it "it should remove the directory" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- FileUtils.expects(:rm_rf).with(@path)
- @provider.destroy
+ expects_rm_rf
+ provider.destroy
end
end
- describe "when checking existence" do
+ describe "checking existence" do
it "should check for the directory" do
- @resource.expects(:value).with(:path).returns(@path)
- File.expects(:directory?).with(@path)
- @provider.exists?
+ expects_directory?(true, File.join(resource.value(:path), '.svn'))
+ provider.exists?
end
end
- describe "when checking the revision property" do
+ describe "checking the revision property" do
+ before do
+ provider.expects('svn').with('info').returns(fixture(:svn_info))
+ end
it "should use 'svn info'" do
- @resource.expects(:value).with(:path).returns(@path)
- @provider.expects('svn').with('info').returns(fixture(:svn_info))
- Dir.expects(:chdir).with(@path).yields
- @provider.revision.should == '4'
+ expects_chdir
+ provider.revision.should == '4'
end
end
- describe "when setting the revision property" do
+ describe "setting the revision property" do
+ before do
+ @revision = '30'
+ end
it "should use 'svn update'" do
- @resource.expects(:value).with(:path).returns(@path)
- @provider.expects('svn').with('update', '-r', '30')
- Dir.expects(:chdir).with(@path).yields
- @provider.revision = '30'
+ expects_chdir
+ provider.expects('svn').with('update', '-r', @revision)
+ provider.revision = @revision
end
end