Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 03210dff56
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (58 sloc) 2.245 kb
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',
'LICENSE' => 'text/plain',
}.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 value from mime type when original_filename provided" do
assert_equal 'audio/mpeg', Wand.wave('some_temp_file', :original_filename => 'test.mp3')
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
should "support old file output format" do
Wand.expects(:execute_file_cmd).returns("text/plain; charset=us-ascii\n")
assert_equal "text/plain", Wand.wave('')
end
should "return nil if file output matches cannot" do
Wand.expects(:execute_file_cmd).returns("cannot open file")
assert_equal nil, Wand.wave('')
end
end
end
Jump to Line
Something went wrong with that request. Please try again.