forked from mimemagicrb/mimemagic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Mendler
committed
Dec 20, 2009
1 parent
02b22e2
commit d0a68fd
Showing
1 changed file
with
23 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
gem 'test-unit', '>= 0' | ||
gem 'test-spec', '>= 0' | ||
require 'test/unit' | ||
require 'test/spec' | ||
require 'mimemagic' | ||
|
||
class TC_MimeMagic < Test::Unit::TestCase | ||
def test_text? | ||
assert MimeMagic.new('text/plain').text? | ||
assert MimeMagic.new('text/html').text? | ||
assert !MimeMagic.new('application/octet-stream').text? | ||
assert !MimeMagic.new('image/png').text? | ||
describe 'MimeMagic' do | ||
it 'should have text? helper' do | ||
MimeMagic.new('text/plain').should.be.text | ||
MimeMagic.new('text/html').should.be.text | ||
MimeMagic.new('application/octet-stream').should.be.not.text | ||
MimeMagic.new('image/png').should.be.not.text | ||
end | ||
|
||
def test_child_of? | ||
assert MimeMagic.new('text/html').child_of?('text/plain') | ||
assert MimeMagic.new('text/x-java').child_of?('text/plain') | ||
it 'should have hierarchy' do | ||
MimeMagic.new('text/html').should.be.child_of 'text/plain' | ||
MimeMagic.new('text/x-java').should.be.child_of 'text/plain' | ||
end | ||
|
||
def test_extensions | ||
assert_equal %w(htm html), MimeMagic.new('text/html').extensions | ||
it 'should have extensions' do | ||
MimeMagic.new('text/html').extensions.should == %w(htm html) | ||
end | ||
|
||
def test_by_extension | ||
assert_equal 'text/html', MimeMagic.by_extension('html').to_s | ||
assert_equal 'application/x-ruby', MimeMagic.by_extension('rb').to_s | ||
assert_nil MimeMagic.by_extension('crazy') | ||
assert_nil MimeMagic.by_extension('') | ||
it 'should recognize extensions' do | ||
MimeMagic.by_extension('html').to_s.should == 'text/html' | ||
MimeMagic.by_extension('rb').to_s.should == 'application/x-ruby' | ||
MimeMagic.by_extension('crazy').should == nil | ||
MimeMagic.by_extension('').should == nil | ||
end | ||
|
||
def test_by_magic | ||
assert_equal 'application/x-executable', MimeMagic.by_magic(File.open('/bin/ls')).to_s | ||
assert_equal 'application/x-sharedlib', MimeMagic.by_magic(File.open('/lib/libc.so.6')).to_s | ||
it 'should recognize by magic' do | ||
MimeMagic.by_magic(File.open('/bin/ls')).to_s.should == 'application/x-executable' | ||
MimeMagic.by_magic(File.open('/lib/libc.so.6')).to_s.should == 'application/x-sharedlib' | ||
end | ||
end |