Sha256: 462ca6eaaf5084f93796509a576db60e7f715d85b44b376271ec65f36b8241fa

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

require 'minitest/autorun'
require 'rack/mime'

describe Rack::Mime do

  it "should return the fallback mime-type for files with no extension" do
    fallback = 'image/jpg'
    Rack::Mime.mime_type(File.extname('no_ext'), fallback).must_equal fallback
  end

  it "should always return 'application/octet-stream' for unknown file extensions" do
    unknown_ext = File.extname('unknown_ext.abcdefg')
    Rack::Mime.mime_type(unknown_ext).must_equal 'application/octet-stream'
  end

  it "should return the mime-type for a given extension" do
    # sanity check. it would be infeasible test every single mime-type.
    Rack::Mime.mime_type(File.extname('image.jpg')).must_equal 'image/jpeg'
  end

  it "should support null fallbacks" do
    Rack::Mime.mime_type('.nothing', nil).must_equal nil
  end

  it "should match exact mimes" do
    Rack::Mime.match?('text/html', 'text/html').must_equal true
    Rack::Mime.match?('text/html', 'text/meme').must_equal false
    Rack::Mime.match?('text', 'text').must_equal true
    Rack::Mime.match?('text', 'binary').must_equal false
  end

  it "should match class wildcard mimes" do
    Rack::Mime.match?('text/html', 'text/*').must_equal true
    Rack::Mime.match?('text/plain', 'text/*').must_equal true
    Rack::Mime.match?('application/json', 'text/*').must_equal false
    Rack::Mime.match?('text/html', 'text').must_equal true
  end

  it "should match full wildcards" do
    Rack::Mime.match?('text/html', '*').must_equal true
    Rack::Mime.match?('text/plain', '*').must_equal true
    Rack::Mime.match?('text/html', '*/*').must_equal true
    Rack::Mime.match?('text/plain', '*/*').must_equal true
  end

  it "should match type wildcard mimes" do
    Rack::Mime.match?('text/html', '*/html').must_equal true
    Rack::Mime.match?('text/plain', '*/plain').must_equal true
  end

end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_mime.rb
abaci-0.3.0 vendor/bundle/gems/rack-2.0.1/test/spec_mime.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/rack-2.0.1/test/spec_mime.rb
rack-2.0.1 test/spec_mime.rb
rack-2.0.0.rc1 test/spec_mime.rb
rack-2.0.0.alpha test/spec_mime.rb