Initial check-in.

This commit is contained in:
Karl Matthias
2012-04-04 10:15:53 +01:00
commit 694fba3ea3
9 changed files with 327 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
require 'capistrano'
require 'capistrano-spec'
require 'fileutils'
mypath = File.expand_path(File.dirname(__FILE__))
require File.expand_path(File.join(mypath, '..', 'lib', 'capistrano', 'deploy_tags'))
describe Capistrano::DeployTags do
let(:configuration) { Capistrano::Configuration.new }
let(:tmpdir) { "/tmp/#{$$}" }
let(:mypath) { mypath }
before :each do
Capistrano::DeployTags.load_into(configuration)
end
def with_clean_repo(&block)
FileUtils.rm_rf tmpdir
FileUtils.mkdir tmpdir
FileUtils.chdir tmpdir
raise unless system("/usr/bin/tar xzf #{File.join(mypath, 'fixtures', 'git-fixture.tar.gz')}")
FileUtils.chdir "#{tmpdir}/git-fixture"
yield
FileUtils.rm_rf tmpdir
end
context "prepare_tree" do
it "raises an error when not in a git tree" do
FileUtils.chdir '/tmp'
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should raise_error('git checkout master failed!')
end
context "with a clean git tree" do
it "raises an error if :stage or :branch are undefined" do
with_clean_repo do
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should raise_error('define :branch or :stage')
end
end
it "does not raise an error when run from a clean tree" do
with_clean_repo do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should_not raise_error
end
end
end
end
context "tagdeploy" do
before :each do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
end
it "does not raise an error when run from a clean tree" do
with_clean_repo do
lambda { configuration.find_and_execute_task('git:tagdeploy') }.should_not raise_error
end
end
it "adds appropriate git tags" do
with_clean_repo do
configuration.find_and_execute_task('git:tagdeploy')
tags = `git tag -l`.split(/\n/).sort
tags.should have(2).items
tags.first.should =~ /^test-\d{4}\.\d{2}\.\d{2}/
tags.last.should == 'test-latest'
end
end
end
end
Binary file not shown.