Permalink
Browse files

Make Lint show proper errors for headers

  • Loading branch information...
1 parent ebefdb2 commit 6f500ddd3bcbd46218a01c408572ad168fd2902a @julik julik committed Jul 12, 2008
Showing with 11 additions and 8 deletions.
  1. +6 −3 lib/rack/lint.rb
  2. +5 −5 test/spec_rack_lint.rb
View
@@ -308,7 +308,9 @@ def check_status(status)
## === The Headers
def check_headers(header)
## The header must respond to each, and yield values of key and value.
- assert("header should respond to #each") { header.respond_to? :each }
+ assert("headers object should respond to #each, but doesn't (got #{header.class} as headers)") {
+ header.respond_to? :each
+ }
header.each { |key, value|
## The header keys must be Strings.
assert("header key must be a string, was #{key.class}") {
@@ -325,10 +327,11 @@ def check_headers(header)
assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ }
##
## The values of the header must respond to #each.
- assert("header values must respond to #each") { value.respond_to? :each }
+ assert("header values must respond to #each, but the value of " +
+ "'#{key}' doesn't (is #{value.class})") { value.respond_to? :each }
value.each { |item|
## The values passed on #each must be Strings
- assert("header values must consist of Strings") {
+ assert("header values must consist of Strings, but '#{key}' also contains a #{item.class}") {
item.instance_of?(String)
}
## and not contain characters below 037.
View
@@ -136,14 +136,14 @@ def env(*args)
[200, Object.new, ""]
}).call(env({}))
}.should.raise(Rack::Lint::LintError).
- message.should.match(/should respond to #each/)
+ message.should.equal("headers object should respond to #each, but doesn't (got Object as headers)")
lambda {
Rack::Lint.new(lambda { |env|
[200, {true=>false}, ""]
}).call(env({}))
}.should.raise(Rack::Lint::LintError).
- message.should.match(/header key must be a string/)
+ message.should.equal("header key must be a string, was TrueClass")
lambda {
Rack::Lint.new(lambda { |env|
@@ -171,21 +171,21 @@ def env(*args)
[200, {"..%%quark%%.." => "text/plain"}, ""]
}).call(env({}))
}.should.raise(Rack::Lint::LintError).
- message.should.match(/invalid header/)
+ message.should.equal("invalid header name: ..%%quark%%..")
lambda {
Rack::Lint.new(lambda { |env|
[200, {"Foo" => Object.new}, ""]
}).call(env({}))
}.should.raise(Rack::Lint::LintError).
- message.should.match(/must respond to #each/)
+ message.should.equal("header values must respond to #each, but the value of 'Foo' doesn't (is Object)")
lambda {
Rack::Lint.new(lambda { |env|
[200, {"Foo" => [1,2,3]}, ""]
}).call(env({}))
}.should.raise(Rack::Lint::LintError).
- message.should.match(/must consist of Strings/)
+ message.should.equal("header values must consist of Strings, but 'Foo' also contains a Fixnum")
lambda {

0 comments on commit 6f500dd

Please sign in to comment.