summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2020-01-14 16:42:37 -0800
committerGitHub <noreply@github.com>2020-01-14 16:42:37 -0800
commitf83d84117724ff55b7e7bab32439394513d67ea2 (patch)
tree3a848a50317225b0698be57832a603a4762ab92c
parent4ebd70b243d79cecda1ba55abce8e2ead78395d7 (diff)
parent6ab28c22b065b19b45b068f030b84a8bdb89b145 (diff)
downloadrack-f83d84117724ff55b7e7bab32439394513d67ea2.tar.gz
Merge pull request #1483 from jeremyevans/lint-response-array
Make Rack::Lint check response is array with 3 elements
-rw-r--r--lib/rack/lint.rb10
-rw-r--r--test/spec_lint.rb16
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb
index 9b739f98..20491c36 100644
--- a/lib/rack/lint.rb
+++ b/lib/rack/lint.rb
@@ -48,7 +48,15 @@ module Rack
env[RACK_ERRORS] = ErrorWrapper.new(env[RACK_ERRORS])
## and returns an Array of exactly three values:
- status, headers, @body = @app.call(env)
+ ary = @app.call(env)
+ assert("response #{ary.inspect} is not an Array , but #{ary.class}") {
+ ary.kind_of? Array
+ }
+ assert("response array #{ary.inspect} has #{ary.size} elements instead of 3") {
+ ary.size == 3
+ }
+
+ status, headers, @body = ary
## The *status*,
check_status status
## the *headers*,
diff --git a/test/spec_lint.rb b/test/spec_lint.rb
index 192f260f..82de1c1d 100644
--- a/test/spec_lint.rb
+++ b/test/spec_lint.rb
@@ -163,6 +163,22 @@ describe Rack::Lint do
message.must_match(/does not respond to #puts/)
end
+ it "notice response errors" do
+ lambda {
+ Rack::Lint.new(lambda { |env|
+ ""
+ }).call(env({}))
+ }.must_raise(Rack::Lint::LintError).
+ message.must_include('response "" is not an Array , but String')
+
+ lambda {
+ Rack::Lint.new(lambda { |env|
+ [nil, nil, nil, nil]
+ }).call(env({}))
+ }.must_raise(Rack::Lint::LintError).
+ message.must_include('response array [nil, nil, nil, nil] has 4 elements instead of 3')
+ end
+
it "notice status errors" do
lambda {
Rack::Lint.new(lambda { |env|