Sha256: 5d8298ba237f1aebd09db4357e9be4b40ff22704def07a684e204a3f950301ab

Contents?: true

Size: 1.08 KB

Versions: 90

Compression:

Stored size: 1.08 KB

Contents

require File.dirname(__FILE__) + '/helper'

context "Custom Errors" do

  setup do
    Sinatra.application = nil
  end

  specify "override the default 404" do

    get_it '/'
    should.be.not_found
    body.should.equal '<h1>Not Found</h1>'

    error Sinatra::NotFound do
      'Custom 404'
    end

    get_it '/'
    should.be.not_found
    body.should.equal 'Custom 404'

  end

  specify "override the default 500" do
    Sinatra.application.options.raise_errors = false

    get '/' do
      raise 'asdf'
    end

    get_it '/'
    status.should.equal 500
    body.should.equal '<h1>Internal Server Error</h1>'


    error do
      'Custom 500 for ' + request.env['sinatra.error'].message
    end

    get_it '/'

    get_it '/'
    status.should.equal 500
    body.should.equal 'Custom 500 for asdf'

    Sinatra.application.options.raise_errors = true
  end

  class UnmappedError < RuntimeError; end

  specify "should bring unmapped error back to the top" do
    get '/' do
      raise UnmappedError, 'test'
    end

    assert_raises(UnmappedError) do
      get_it '/'
    end
  end

end

Version data entries

90 entries across 90 versions & 14 rubygems

Version Path
nbudin-castronaut-0.7.5 vendor/sinatra/compat/custom_error_test.rb
sinatra-0.9.6 compat/custom_error_test.rb
sinatra-0.9.5 compat/custom_error_test.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/sinatra-0.9.4/compat/custom_error_test.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/custom_error_test.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.10.17 vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.10.16 vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.10.15 vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
middleman-0.10.14 vendor/gems/gems/sinatra-0.9.4/compat/custom_error_test.rb
sinatra-0.9.4 compat/custom_error_test.rb
sinatra-0.3.2 test/custom_error_test.rb
sinatra-0.9.0.2 compat/custom_error_test.rb
sinatra-0.3.0 test/custom_error_test.rb