Sha256: 1dbb62d113cbc26362ca461212e5ee4cc9a20896a4f6536b83d466661ebd93c9

Contents?: true

Size: 1.81 KB

Versions: 128

Compression:

Stored size: 1.81 KB

Contents

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).should.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).should.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')).should.equal 'image/jpeg'
  end

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

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

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

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

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

end

Version data entries

128 entries across 112 versions & 32 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/test/spec_mime.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/rack-1.6.5/test/spec_mime.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/rack-1.6.5/test/spec_mime.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/rack-1.6.5/test/spec_mime.rb
arcabouco-0.2.13 vendor/bundle/gems/rack-1.6.4/test/spec_mime.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/rack-1.6.5/test/spec_mime.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/rack-1.6.5/test/spec_mime.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/rack-1.6.5/test/spec_mime.rb
rack-1.6.5 test/spec_mime.rb
tdiary-5.0.2 vendor/bundle/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/rack-1.6.4/test/spec_mime.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/rack-1.6.4/test/spec_mime.rb
tdiary-5.0.1 vendor/bundle/gems/rack-1.6.4/test/spec_mime.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/test/spec_mime.rb