diff options
author | James Tucker <jftucker@gmail.com> | 2014-07-13 14:24:32 -0700 |
---|---|---|
committer | James Tucker <jftucker@gmail.com> | 2014-07-13 14:25:03 -0700 |
commit | 6f1a4a4873fbf2fd54f2582a9e388b96722e21de (patch) | |
tree | fdfe183d4342c50573adbff1af30c80d20dd404e | |
parent | 01428fe54f003996dc04811fe0216de2258a2e09 (diff) | |
download | rack-6f1a4a4873fbf2fd54f2582a9e388b96722e21de.tar.gz |
correct typo and refactor tests for coverage
Closes #592
-rw-r--r-- | test/spec_showexceptions.rb | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/test/spec_showexceptions.rb b/test/spec_showexceptions.rb index c5e2cb02..6400fdb9 100644 --- a/test/spec_showexceptions.rb +++ b/test/spec_showexceptions.rb @@ -26,7 +26,7 @@ describe Rack::ShowExceptions do res.should =~ /ShowExceptions/ end - it "responds with plain text to requests not specifically accepting HTML" do + it "responds with HTML only to requests accepting HTML" do res = nil req = Rack::MockRequest.new( @@ -34,39 +34,32 @@ describe Rack::ShowExceptions do lambda{|env| raise RuntimeError, "It was never supposed to work" } )) - lambda{ - res = req.get( "/", "HTTP_ACCECPT" => "*/*") - }.should.not.raise - - res.should.be.a.server_error - res.status.should.equal 500 - - res.content_type.should.equal "text/plain" - - res.body.should.include "RuntimeError: It was never supposed to work\n" - res.body.should.include __FILE__ - end - - it "responds with HTML to requests specifically accepting HTML" do - res = nil - - req = Rack::MockRequest.new( - show_exceptions( - lambda{|env| raise RuntimeError, "It was never supposed to work" } - )) - - lambda{ - res = req.get("/", "HTTP_ACCEPT" => "text/html") - }.should.not.raise - - res.should.be.a.server_error - res.status.should.equal 500 - - res.content_type.should.equal "text/html" - - res.body.should.include "RuntimeError" - res.body.should.include "It was never supposed to work" - res.body.should.include Rack::Utils.escape_html(__FILE__) + [ + # Serve text/html when the client accepts text/html + ["text/html", ["/", "HTTP_ACCEPT" => "text/html"]], + ["text/html", ["/", "HTTP_ACCEPT" => "*/*"]], + # Serve text/plain when the client does not accept text/html + ["text/plain", ["/"]], + ["text/plain", ["/", "HTTP_ACCEPT" => "application/json"]] + ].each do |exmime, rargs| + lambda{ + res = req.get(*rargs) + }.should.not.raise + + res.should.be.a.server_error + res.status.should.equal 500 + + res.content_type.should.equal exmime + + res.body.should.include "RuntimeError" + res.body.should.include "It was never supposed to work" + + if exmime == "text/html" + res.body.should.include '</html>' + else + res.body.should.not.include '</html>' + end + end end it "handles exceptions without a backtrace" do |