Sha256: fb7fc6c1f11260ab74a983e28c3f08760d4ba3b128191cec687c5ff07f9a1957

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'helper'

class TestWand < Test::Unit::TestCase
  context "Wand" do
    setup do
      Wand.executable = `which file`.chomp
    end

    {
      'AVGARDD.svg'    => 'image/svg+xml',
      'compressed.zip' => 'application/zip',
      'favicon.ico'    => 'image/vnd.microsoft.icon',
      'index.html'     => 'text/html',
      'jquery.js'      => 'application/javascript',
      'ol_tiny.jpg'    => 'image/jpeg',
      'ol_tiny.png'    => 'image/png',
      'styles.css'     => 'text/css',
    }.each_pair do |name, type|
      should "use mime type gem if it returns type #{name}" do
        assert_equal type, Wand.wave(FilePath.join(name).expand_path.to_s)
      end
    end

    {
      'example.m4r'    => 'audio/mp4',
      'AVGARDD.eot'    => 'application/octet-stream',
      'AVGARDD.ttf'    => 'application/octet-stream',
      'AVGARDD.woff'   => 'application/octet-stream',
    }.each_pair do |name, type|
      should "fall back to unix file command when mime type returns nothing for #{name}" do
        assert_equal type, Wand.wave(FilePath.join(name).expand_path.to_s)
      end
    end

    should "return nil when mime type and file fail" do
      assert_nil Wand.wave('AVGARDD.eot')
    end

    should "detect executable" do
      assert_equal '/usr/bin/file', Wand.executable
    end

    should "allow setting the executable" do
      Wand.executable = '/usr/local/bin/file'
      assert_equal '/usr/local/bin/file', Wand.executable
    end

    should "strip newlines and such" do
      Wand.expects(:execute_file_cmd).returns("image/jpeg\n")
      assert_equal "image/jpeg", Wand.wave(FilePath.join(name).expand_path.to_s)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wand-0.2.1 test/test_wand.rb