diff options
author | Julik <me@julik.nl> | 2008-07-12 12:47:35 +0200 |
---|---|---|
committer | Julik <me@julik.nl> | 2008-07-12 12:47:35 +0200 |
commit | 6f500ddd3bcbd46218a01c408572ad168fd2902a (patch) | |
tree | f51f9e7568c30045a01f45d6c548d5523710d581 | |
parent | ebefdb2fa7d92eaa58122542c37f7cfda3ae7c3f (diff) | |
download | rack-6f500ddd3bcbd46218a01c408572ad168fd2902a.tar.gz |
Make Lint show proper errors for headers
-rw-r--r-- | lib/rack/lint.rb | 9 | ||||
-rw-r--r-- | test/spec_rack_lint.rb | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb index b5232e00..d55e4b4a 100644 --- a/lib/rack/lint.rb +++ b/lib/rack/lint.rb @@ -308,7 +308,9 @@ module Rack ## === 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 @@ module Rack 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. diff --git a/test/spec_rack_lint.rb b/test/spec_rack_lint.rb index e863559c..f3fbd3b2 100644 --- a/test/spec_rack_lint.rb +++ b/test/spec_rack_lint.rb @@ -136,14 +136,14 @@ context "Rack::Lint" do [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 @@ context "Rack::Lint" do [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 { |