spec/hillary/slug_spec.rb in hillary-0.0.3 vs spec/hillary/slug_spec.rb in hillary-0.0.4
- old
+ new
@@ -15,13 +15,14 @@
)
end
let(:out){StringIO.new}
let(:logger) do
Logger.new(out).tap do |logger|
+ logger.formatter = proc{|_, _, _, msg| msg + "\n"}
end
end
- let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket')}
+ let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket', exists?: true)}
let(:path){File.expand_path('../../tmp/g3', __FILE__)}
describe '.build' do
context 'when the version is not sluggable' do
before(:each){allow(version).to receive(:sluggable?){false}}
@@ -43,24 +44,26 @@
end
end
end
describe '#build' do
+ let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
+ let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
+
+ before(:each){FileUtils.mkdir_p(path)}
+ after(:each){FileUtils.rm_rf(path)}
+
context 'when branch is dev' do
subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
- let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
- let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
describe 'when everything is successful' do
before(:each) do
- FileUtils.mkdir_p(path)
allow(bucket).to receive(:write)
end
after(:each) do
FileUtils.rm_rf(slug_path)
- FileUtils.rm_rf(path)
end
it 'creates the slug' do
slug.build
@@ -76,18 +79,20 @@
it 'logs information about what is happening' do
slug.build
expect(out.string).to eq(
"Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
+ "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
'Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
"to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"
)
end
end
describe 'when archiving fails' do
it 'raises an error' do
+ FileUtils.rm_rf(path)
expect{slug.build}.to raise_error(Hillary::Shellable::ExecutionError)
end
end
end
@@ -105,21 +110,58 @@
)
end
subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
- it 'copies the canonical slug to rc slug name' do
- expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
+ context 'when the canonical slug exists' do
+ it 'copies the canonical slug to rc slug name' do
+ expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
- slug.build
+ slug.build
+ end
+
+ it 'logs information about what is happening' do
+ slug.build
+
+ expect(out.string).to eq(
+ 'Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
+ "to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
+ )
+ end
end
- it 'logs information about what is happening' do
- slug.build
+ context 'when the canonical slug does not exist' do
+ before(:each){allow(bucket).to receive(:exists?).and_return(false)}
- expect(out.string).to eq('Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
- "to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
- )
+ it 'creates the slug' do
+ slug.build
+
+ expect(File.exist?(slug_path)).to eq(true)
+ end
+
+ it 'writes the slug to the bucket' do
+ expect(bucket).to receive(:write).with('dev/' + slug_name, slug_path)
+
+ slug.build
+ end
+
+ it 'copies the canonical slug to rc slug name' do
+ expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
+
+ slug.build
+ end
+
+ it 'logs information about what is happening' do
+ slug.build
+
+ expect(out.string).to eq(
+ "Unable to find slug gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
+ "Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
+ "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
+ "Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
+ "Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
+ )
+ end
end
end
context 'when branch is master and is a production build' do
let(:version) do