| Class | FileTypeTest |
| In: |
lib/file_type.rb
|
| Parent: | Test::Unit::TestCase |
# File lib/file_type.rb, line 353 def assert_extract ( type, command, file ) assert_nothing_raised { @inp = FileType.guess(file) } assert(@inp.extractable?, "#@inp not extractable") assert_nothing_raised { @res = @inp.extract } assert_kind_of(FileType.const_get(type), @res) assert_match(command, @mr.log.first.to_sh) assert_equal(1, @mr.log.size, "Mock log size != 1") end
# File lib/file_type.rb, line 344 def assert_guess ( type, *files ) files.flatten.each do |file| assert_nothing_raised do @file = FileType.guess(file) end assert_kind_of(FileType.const_get(type), @file) end end
# File lib/file_type.rb, line 370 def assert_install ( command, file, *args ) assert_nothing_raised { @inp = FileType.guess(file) } assert(@inp.installable?, "#@inp not installable") assert_nothing_raised { @res = @inp.install(*args) } assert_match(command, @mr.log.last.to_sh) end
# File lib/file_type.rb, line 362 def assert_real_extract ( type, file ) FileType::Generic.runner = OCmd::Runners::System.new assert_nothing_raised { @inp = FileType.guess(file) } assert(@inp.extractable?, "#@inp not extractable") assert_nothing_raised { @res = @inp.extract } assert_kind_of(FileType.const_get(type), @res) end
# File lib/file_type.rb, line 333 def setup @tmp = TempPath.new (@tmp + 'foo').mkpath @mr = OCmd::Runners::System.new @mr.make_mock do puts "#@tmp/foo/bar/baz\n#@tmp/foo\n#@tmp/foo/f/f/foo/baz" end FileType::Generic.runner = @mr @fixtures = __FILE__.to_path.dirname.parent + 'test/fixtures' end
# File lib/file_type.rb, line 409 def test_dir TempPath.new do |tmp| tmp.mkpath assert_guess :Directory, tmp, '.', '/', '..' end end
# File lib/file_type.rb, line 419 def test_extract_bz2 assert_extract :Unknown, /^bzip2 -d -c [^%]* > [^%]*$/, @fixtures/'foo.bz2' end
# File lib/file_type.rb, line 416 def test_extract_gz assert_extract :Ruby, /^gzip -d -c [^%]* > [^%]*$/, @fixtures/'foo.rb.gz' end
# File lib/file_type.rb, line 438 def test_extract_tar assert_extract :Directory, /^tar xvf [^%]*foo.tar -C [^%]* > [^%]*$/, @fixtures/'foo.tar' end
# File lib/file_type.rb, line 425 def test_extract_tar_bz2 assert_extract :Directory, /^\(bzip2 -c -d [^%]*foo.tar.bz2\) \| \(tar xvf - -C [^%]* > [^%]*\)$/, @fixtures/'foo.tar.bz2' end
# File lib/file_type.rb, line 433 def test_extract_tar_gz assert_extract :Directory, /^tar xvzf [^%]*foo.tar.gz -C .*foo.* > .*log.*$/, @fixtures/'foo.tar.gz' assert_real_extract :Directory, @fixtures/'foo.tar.gz' end
# File lib/file_type.rb, line 422 def test_extract_zip assert_extract :Gz, /^unzip -p [^%]* > [^%]*$/, @fixtures/'foo.gz.zip' end
# File lib/file_type.rb, line 378 def test_gz assert_guess :Gz, %w[ foo.gz foo.z foo.Z foo-z foo-gz foo_z ] end
# File lib/file_type.rb, line 443 def test_install_gem assert_install(/^gem install foo.gem$/, 'foo.gem') assert_install(/^gem install foo.gem --install-dir \/tmp$/, 'foo.gem', '/tmp') end
# File lib/file_type.rb, line 449 def test_longest_common_path assert_nothing_raised do res = @fixtures/'tar.gz.log' @longest = FileType::ExtractableDir.longest_common_path(res) end assert_equal(['core_ex-0.1.4'], @longest) end
# File lib/file_type.rb, line 430 def test_real_extract_tar_bz2 assert_real_extract :Directory, @fixtures/'foo.tar.bz2' end
# File lib/file_type.rb, line 387 def test_tar_bz2 assert_guess :TarBz2, %w[ foo.tar.bz2 foo.tbz2 foo/bar.tbz ] end
# File lib/file_type.rb, line 390 def test_tar_gz assert_guess :TarGz, %w[ foo.tar.gz foo.tgz foo/bar.tar.gz foo.tar.Z ] end
# File lib/file_type.rb, line 405 def test_unknown assert_guess :Unknown, 'foo.dne', 'foo', '.foo' assert(! @file.extractable?, "#@file is extractable") end