require 'test/unit' require 'mocha' require 'capistrano' require 'capistrano_fixes' class Capistrano::Fixes::SCPAsDefaultTransferProtocolTest < Test::Unit::TestCase M = Capistrano::Fixes::SCPAsDefaultTransferProtocol class FileTransfer CALLS = [] def transfer(*args) CALLS << args end include M end def test_transfer tr = FileTransfer.new tr.transfer(:up, "from", "to") assert_equal [[:up, "from", "to", {:via => :scp, :recursive => true}]], FileTransfer::CALLS ensure FileTransfer::CALLS.clear end end class Capistrano::Fixes::CommandlessCompressionTest < Test::Unit::TestCase M = Capistrano::Fixes::CommandlessCompression class Strategy Compression = Struct.new(:compress_command) def deploy! system(compress(:file, :directory).join(" ")) end private def compression Compression.new(%w(tar czf)) end # Copied from Capistrano source code. def compress(file, directory) compression.compress_command + [file, directory] end include M end def test_deploy! strategy = Strategy.new # Fake absence of `tar' to trigger the use of command-less tarring Kernel.stubs(:system).with("which tar > /dev/null 2>&1").returns false # Expect command-less tarring M::Tarring.expects(:compress).with(:file, :directory) strategy.deploy! end end class Capistrano::Fixes::CommandlessCompression::TarringTest < Test::Unit::TestCase M = Capistrano::Fixes::CommandlessCompression::Tarring def setup @tmp = File.dirname(__FILE__) + "/tmp" # Fix for when the test is not run individually: @tmp = File.expand_path(@tmp) teardown FileUtils.mkdir_p(@tmp) end def teardown FileUtils.rm_rf(@tmp) end def test_compress FileUtils.mkdir("#{@tmp}/foo") FileUtils.mkdir("#{@tmp}/foo/bar") FileUtils.touch("#{@tmp}/foo/bar/abc") FileUtils.mkdir("#{@tmp}/foo/baz") # Compress archive = "#{@tmp}/foo.tgz" M.compress(archive, "#{@tmp}/foo") # Uncompress unpack_dir = "#{@tmp}/unpack" FileUtils.mkdir(unpack_dir) Dir.chdir(unpack_dir) do system(*M::DECOMPRESSION_COMMAND + [archive]) end expected = [ "#{unpack_dir}/foo", "#{unpack_dir}/foo/bar", "#{unpack_dir}/foo/bar/abc", "#{unpack_dir}/foo/baz" ] assert_equal expected, Dir["#{unpack_dir}/**/*"] end end