Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap test apps in Rack::Lint and fix uncovered errors (second pass)
Update tests for Config, ContentLength, ContentType and Deflater.
- Loading branch information
Lars Gierth
authored and
Lars Gierth
committed
Mar 31, 2012
1 parent
284000f
commit bd43405
Showing
4 changed files
with
72 additions
and
36 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,35 +1,45 @@ | |||
require 'rack/content_type' | require 'rack/content_type' | ||
require 'rack/lint' | |||
require 'rack/mock' | |||
|
|
||
describe Rack::ContentType do | describe Rack::ContentType do | ||
def content_type(app, *args) | |||
Rack::Lint.new Rack::ContentType.new(app, *args) | |||
end | |||
|
|||
def request | |||
Rack::MockRequest.env_for | |||
end | |||
|
|||
should "set Content-Type to default text/html if none is set" do | should "set Content-Type to default text/html if none is set" do | ||
app = lambda { |env| [200, {}, "Hello, World!"] } | app = lambda { |env| [200, {}, "Hello, World!"] } | ||
headers = Rack::ContentType.new(app).call({})[1] | headers = content_type(app).call(request)[1] | ||
headers['Content-Type'].should.equal 'text/html' | headers['Content-Type'].should.equal 'text/html' | ||
end | end | ||
|
|
||
should "set Content-Type to chosen default if none is set" do | should "set Content-Type to chosen default if none is set" do | ||
app = lambda { |env| [200, {}, "Hello, World!"] } | app = lambda { |env| [200, {}, "Hello, World!"] } | ||
headers = | headers = | ||
Rack::ContentType.new(app, 'application/octet-stream').call({})[1] | content_type(app, 'application/octet-stream').call(request)[1] | ||
headers['Content-Type'].should.equal 'application/octet-stream' | headers['Content-Type'].should.equal 'application/octet-stream' | ||
end | end | ||
|
|
||
should "not change Content-Type if it is already set" do | should "not change Content-Type if it is already set" do | ||
app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] } | app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] } | ||
headers = Rack::ContentType.new(app).call({})[1] | headers = content_type(app).call(request)[1] | ||
headers['Content-Type'].should.equal 'foo/bar' | headers['Content-Type'].should.equal 'foo/bar' | ||
end | end | ||
|
|
||
should "detect Content-Type case insensitive" do | should "detect Content-Type case insensitive" do | ||
app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] } | app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] } | ||
headers = Rack::ContentType.new(app).call({})[1] | headers = content_type(app).call(request)[1] | ||
headers.to_a.select { |k,v| k.downcase == "content-type" }. | headers.to_a.select { |k,v| k.downcase == "content-type" }. | ||
should.equal [["CONTENT-Type","foo/bar"]] | should.equal [["CONTENT-Type","foo/bar"]] | ||
end | end | ||
|
|
||
should "not set Content-Type on 304 responses" do | should "not set Content-Type on 304 responses" do | ||
app = lambda { |env| [304, {}, []] } | app = lambda { |env| [304, {}, []] } | ||
response = Rack::ContentType.new(app, "text/html").call({}) | response = content_type(app, "text/html").call(request) | ||
response[1]['Content-Type'].should.equal nil | response[1]['Content-Type'].should.equal nil | ||
end | end | ||
end | end |
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