Permalink
Browse files

test coverage

  • Loading branch information...
1 parent 4398926 commit 6b0a63e4fd11a79775140835e3bb28a795f738e0 @Arie committed Mar 12, 2013
View
@@ -1,3 +1,2 @@
#!/usr/bin/env ruby
-SimpleCov.start 'rails' do
-end
+SimpleCov.start 'rails'
@@ -59,12 +59,6 @@ def zip
server.execute("zip --junk-paths #{remote_zip_name} #{shell_escaped_files_to_zip.join(' ')}")
end
- private
-
- def shell_escaped_files_to_zip
- files_to_zip.collect { |file| file.shellescape }
- end
-
def download_zip_from_remote_server
server.copy_from_server([remote_zip_name], zipfile_name_and_path)
end
@@ -77,8 +71,14 @@ def remove_zip_file_on_remote_server
server.execute("rm #{remote_zip_name}")
end
+ private
+
def server
reservation.server
end
+ def shell_escaped_files_to_zip
+ files_to_zip.collect { |file| file.shellescape }
+ end
+
end
@@ -5,7 +5,7 @@
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
-SimpleCov.start
+SimpleCov.start 'rails'
require 'cucumber/rails'
require 'cucumber/rspec/doubles'
@@ -71,8 +71,12 @@
subject.stub(:id => 'foo')
subject.stub(:temporary_reservation_config_file => temporary_reservation_file)
subject.should_receive(:upload_configuration).with(temporary_reservation_file)
- File.should_receive(:open).and_return(stub.as_null_object)
- subject.write_configuration(stub, stub)
+ filename = stub
+ content = stub
+ file = stub
+ File.should_receive(:open).and_yield(file)
+ file.should_receive(:write).with(content)
+ subject.write_configuration(filename, content)
end
end
@@ -31,6 +31,24 @@
end
end
+ describe LocalZipFileCreator do
+
+ describe '#zip' do
+
+ it "it adds the files to zip to a zipfile" do
+ zip_file = LocalZipFileCreator.new(reservation, ["foo'bar"])
+ zip_file.stub(:server => server)
+ zip_file.stub(:files_to_zip => ['foo/qux.zip'])
+ zip_file.stub(:zipfile_name_and_path => 'bar.zip')
+ zip_zip_file = stub
+ Zip::ZipFile.should_receive(:open).with(zip_file.zipfile_name_and_path, Zip::ZipFile::CREATE).and_yield(zip_zip_file)
+ zip_zip_file.should_receive(:add).with('qux.zip', 'foo/qux.zip')
+ zip_file.zip
+ end
+
+ end
+ end
+
describe SshZipFileCreator do
it "shell escapes the file names" do
@@ -53,6 +71,41 @@
end
+ describe '#download_zip_from_remote_server' do
+
+ it 'tells the server to download' do
+ zip_file = SshZipFileCreator.new(reservation, ["foo'bar"])
+ zip_file.stub(:server => server)
+ zip_file.stub(:remote_zip_name => 'foo.zip')
+ zip_file.stub(:zipfile_name_and_path => 'bar.zip')
+ server.should_receive(:copy_from_server).with([zip_file.remote_zip_name], zip_file.zipfile_name_and_path)
+ zip_file.download_zip_from_remote_server
+ end
+ end
+
+ describe '#remote_zip_name' do
+
+ it 'generates the remote zip name from the servers tf dir and reservations id' do
+ zip_file = SshZipFileCreator.new(reservation, ["foo'bar"])
+ zip_file.stub(:server => server)
+ reservation.stub(:id => 1337)
+ server.stub(:tf_dir => "foo")
+ zip_file.remote_zip_name.should == "#{server.tf_dir}/logs_and_demos_#{zip_file.reservation.id}.zip"
+ end
+ end
+
+ describe '#remove_zip_file_on_remote_server' do
+
+ it 'removes the remote zip file' do
+ zip_file = SshZipFileCreator.new(reservation, ["foo'bar"])
+ zip_file.stub(:server => server)
+ zip_file.stub(:remote_zip_name => "foo.zip")
+ server.should_receive(:execute).with("rm foo.zip")
+ zip_file.remove_zip_file_on_remote_server
+ end
+ end
+
+
end
end
View
@@ -5,7 +5,7 @@
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
-SimpleCov.start
+SimpleCov.start 'rails'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'

0 comments on commit 6b0a63e

Please sign in to comment.