spec/dockly/build_cache_spec.rb in dockly-1.1.0 vs spec/dockly/build_cache_spec.rb in dockly-1.1.1
- old
+ new
@@ -6,11 +6,11 @@
before do
subject.s3_bucket 'lol'
subject.s3_object_prefix 'swag'
subject.image = image
- subject.hash_command 'md6' # haters come at me
+ subject.hash_command 'md5sum /etc/vim/vimrc'
subject.build_command 'touch lol'
subject.output_dir '/'
end
describe '#execute!' do
@@ -24,12 +24,11 @@
let(:up_to_date) { true }
it "does not have the file lol" do
i = subject.execute!
output = ""
- puts i
- i.run('ls').start.attach { |chunk| output += chunk }
+ i.run('ls').attach { |chunk| output += chunk }
output.should_not include('lol')
end
end
context 'when the object is not up to date' do
@@ -47,21 +46,40 @@
describe "#run_build" do
before do
subject.stub(:push_to_s3)
end
- it "does have the file lol" do
- i = subject.execute!
- output = ""
- i.run('ls').attach { |chunk| output += chunk }
- output.should include('lol')
+ context "when the build succeeds" do
+ it "does have the file lol" do
+ i = subject.run_build
+ output = ""
+ i.run('ls').attach { |chunk| output += chunk }
+ output.should include('lol')
+ end
end
+
+ context "when the build fails" do
+ let!(:image) { subject.image }
+ before do
+ subject.image = double(:image).stub(:run) {
+ stub(:container, { :wait => { 'StatusCode' => 1 } })
+ }
+ end
+
+ after do
+ subject.image = image
+ end
+
+ it "raises an error" do
+ expect { subject.run_build }.to raise_error
+ end
+ end
end
describe '#pull_from_s3' do
- let (:file) { subject.pull_from_s3('hey') }
- let (:object) { double(:object) }
+ let(:file) { subject.pull_from_s3('hey') }
+ let(:object) { double(:object) }
before do
subject.connection.stub(:get_object).and_return object
object.stub(:body).and_return 'hey dad'
end
@@ -97,16 +115,29 @@
describe '#hash_output' do
let(:output) {
"682aa2a07693cc27756eee9751db3903 /etc/vim/vimrc"
}
- before do
- subject.image = image
- subject.hash_command 'md5sum /etc/vim/vimrc'
+ context "when hash command returns successfully" do
+ before do
+ subject.image = image
+ end
+
+ it 'returns the output of the hash_command in the container' do
+ subject.hash_output.should == output
+ end
end
- it 'returns the output of the hash_command in the container' do
- subject.hash_output.should == output
+ context "when hash command returns failure" do
+ before do
+ subject.image = double(:image).stub(:run, {
+ :wait => { 'StatusCode' => 1 }
+ })
+ end
+
+ it 'raises an error' do
+ expect { subject.hash_output }.to raise_error
+ end
end
end
describe '#copy_output_dir' do
let(:container) { Docker::Container.create('Image' => 'base', 'Cmd' => %w[true]) }