Sha256: 5c43574d1fa09566b1d1f5fdfc14338a90e91d84a33743b66e711f3cc0676683
Contents?: true
Size: 1.78 KB
Versions: 13
Compression:
Stored size: 1.78 KB
Contents
require 'assert' require 'deas/show_exceptions' require 'rack/utils' class Deas::ShowExceptions class UnitTests < Assert::Context desc "Deas::ShowExceptions" setup do @middleware_class = Deas::ShowExceptions end subject{ @middleware_class } end class InitTests < UnitTests desc "when init" setup do @app = Factory.sinatra_call @env = { 'deas.error' => Factory.exception } @middleware = @middleware_class.new(@app) end subject{ @middleware } should have_imeths :call, :call! should "return a response for the exception when called" do status, headers, body = subject.call(@env) error_body = Body.new(@env['deas.error']) assert_equal @app.response.status, status assert_equal error_body.size.to_s, headers['Content-Length'] assert_equal error_body.mime_type, headers['Content-Type'] assert_equal [error_body.content], body end should "return the apps response if there isn't an exception" do @env.delete('deas.error') status, headers, body = subject.call(@env) assert_equal @app.response.status, status assert_equal @app.response.headers, headers assert_equal [@app.response.body], body end end class BodyTests < UnitTests desc "Body" setup do @exception = Factory.exception @body = Body.new(@exception) end subject{ @body } should have_readers :content, :size, :mime_type should "know its attributes" do exp_content = "#{@exception.class}: #{@exception.message}\n" \ "#{(@exception.backtrace || []).join("\n")}" assert_equal exp_content, subject.content assert_equal Rack::Utils.bytesize(exp_content), subject.size assert_equal "text/plain", subject.mime_type end end end
Version data entries
13 entries across 13 versions & 1 rubygems