Sha256: da727a20a4beed34340b39ea08250325963b09f121cca6f3be46e2ecd9b9c7a2
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
require 'spec_helper' require 'singleton' module Startback module Web describe CatchAll do include Rack::Test::Methods context 'when used without context' do def app Rack::Builder.new do use CatchAll run ->(env){ raise "Hello error" } end end it 'returns a 500 with json explanation' do get '/' expect(last_response.status).to eql(500) expect(last_response.content_type).to eql("application/json") result = JSON.parse(last_response.body) expect(result).to eql({ "code" => "Startback::Errors::InternalServerError", "description" => "An error occured, sorry" }) end end context 'when used with a context providing an error handler' do class AnError < StandardError end class ErrorHandler include Singleton attr_reader :ex def fatal(ex) @ex = ex end end class MyContextWithErrorHandler < Startback::Context def error_handler ErrorHandler.instance end end def app Rack::Builder.new do use Context::Middleware, context_class: MyContextWithErrorHandler use CatchAll run ->(env){ raise AnError, "Hello error" } end end it 'returns a 500 with json explanation' do get '/' expect(last_response.status).to eql(500) expect(last_response.content_type).to eql("application/json") result = JSON.parse(last_response.body) expect(result).to eql({ "code" => "Startback::Errors::InternalServerError", "description" => "An error occured, sorry" }) expect(ErrorHandler.instance.ex).to be_a(AnError) end end end # CatchAll end # module Web end # module Startback
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
startback-0.3.2 | spec/unit/web/test_catch_all.rb |
startback-0.3.1 | spec/unit/web/test_catch_all.rb |
startback-0.3.0 | spec/unit/web/test_catch_all.rb |