adamwiggins-sinatra 0.8.9 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +8 -7
 - data/CHANGES +211 -1
 - data/LICENSE +1 -1
 - data/README.rdoc +183 -139
 - data/Rakefile +20 -81
 - data/lib/sinatra.rb +5 -1
 - data/lib/sinatra/base.rb +569 -278
 - data/lib/sinatra/main.rb +12 -25
 - data/lib/sinatra/showexceptions.rb +303 -0
 - data/sinatra.gemspec +20 -44
 - data/test/base_test.rb +140 -52
 - data/test/builder_test.rb +14 -17
 - data/test/contest.rb +64 -0
 - data/test/erb_test.rb +42 -16
 - data/test/extensions_test.rb +100 -0
 - data/test/filter_test.rb +85 -13
 - data/test/haml_test.rb +39 -21
 - data/test/helper.rb +76 -0
 - data/test/helpers_test.rb +219 -84
 - data/test/mapped_error_test.rb +168 -146
 - data/test/middleware_test.rb +22 -17
 - data/test/options_test.rb +323 -54
 - data/test/render_backtrace_test.rb +145 -0
 - data/test/request_test.rb +28 -6
 - data/test/response_test.rb +42 -0
 - data/test/result_test.rb +27 -21
 - data/test/route_added_hook_test.rb +59 -0
 - data/test/routing_test.rb +558 -77
 - data/test/sass_test.rb +52 -13
 - data/test/server_test.rb +47 -0
 - data/test/sinatra_test.rb +3 -5
 - data/test/static_test.rb +57 -30
 - data/test/templates_test.rb +74 -25
 - data/test/views/error.builder +3 -0
 - data/test/views/error.erb +3 -0
 - data/test/views/error.haml +3 -0
 - data/test/views/error.sass +2 -0
 - data/test/views/foo/hello.test +1 -0
 - metadata +50 -46
 - data/compat/app_test.rb +0 -300
 - data/compat/application_test.rb +0 -334
 - data/compat/builder_test.rb +0 -101
 - data/compat/custom_error_test.rb +0 -62
 - data/compat/erb_test.rb +0 -136
 - data/compat/events_test.rb +0 -75
 - data/compat/filter_test.rb +0 -30
 - data/compat/haml_test.rb +0 -233
 - data/compat/helper.rb +0 -21
 - data/compat/mapped_error_test.rb +0 -72
 - data/compat/pipeline_test.rb +0 -71
 - data/compat/public/foo.xml +0 -1
 - data/compat/sass_test.rb +0 -57
 - data/compat/sessions_test.rb +0 -39
 - data/compat/streaming_test.rb +0 -121
 - data/compat/sym_params_test.rb +0 -19
 - data/compat/template_test.rb +0 -30
 - data/compat/use_in_file_templates_test.rb +0 -47
 - data/compat/views/foo.builder +0 -1
 - data/compat/views/foo.erb +0 -1
 - data/compat/views/foo.haml +0 -1
 - data/compat/views/foo.sass +0 -2
 - data/compat/views/foo_layout.erb +0 -2
 - data/compat/views/foo_layout.haml +0 -2
 - data/compat/views/layout_test/foo.builder +0 -1
 - data/compat/views/layout_test/foo.erb +0 -1
 - data/compat/views/layout_test/foo.haml +0 -1
 - data/compat/views/layout_test/foo.sass +0 -2
 - data/compat/views/layout_test/layout.builder +0 -3
 - data/compat/views/layout_test/layout.erb +0 -1
 - data/compat/views/layout_test/layout.haml +0 -1
 - data/compat/views/layout_test/layout.sass +0 -2
 - data/compat/views/no_layout/no_layout.builder +0 -1
 - data/compat/views/no_layout/no_layout.haml +0 -1
 - data/lib/sinatra/compat.rb +0 -239
 - data/lib/sinatra/test.rb +0 -112
 - data/lib/sinatra/test/rspec.rb +0 -2
 - data/lib/sinatra/test/spec.rb +0 -2
 - data/lib/sinatra/test/unit.rb +0 -11
 - data/test/reload_test.rb +0 -65
 
    
        data/test/mapped_error_test.rb
    CHANGED
    
    | 
         @@ -1,164 +1,186 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require ' 
     | 
| 
       2 
     | 
    
         
            -
            require 'sinatra/base'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'sinatra/test'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/helper'
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              class FooError < RuntimeError
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
      
 3 
     | 
    
         
            +
            class FooError < RuntimeError
         
     | 
| 
      
 4 
     | 
    
         
            +
            end
         
     | 
| 
       10 
5 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  set :raise_errors, false
         
     | 
| 
       14 
     | 
    
         
            -
                  error(FooError) { 'Foo!' }
         
     | 
| 
       15 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       16 
     | 
    
         
            -
                    raise FooError
         
     | 
| 
       17 
     | 
    
         
            -
                  end
         
     | 
| 
       18 
     | 
    
         
            -
                }
         
     | 
| 
       19 
     | 
    
         
            -
                get '/'
         
     | 
| 
       20 
     | 
    
         
            -
                status.should.equal 500
         
     | 
| 
       21 
     | 
    
         
            -
                body.should.equal 'Foo!'
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
            class FooNotFound < Sinatra::NotFound
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
       23 
8 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                  error(Exception) { 'Exception!' }
         
     | 
| 
       28 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       29 
     | 
    
         
            -
                    raise FooError
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
       31 
     | 
    
         
            -
                }
         
     | 
| 
       32 
     | 
    
         
            -
                get '/'
         
     | 
| 
       33 
     | 
    
         
            -
                status.should.equal 500
         
     | 
| 
       34 
     | 
    
         
            -
                body.should.equal 'Exception!'
         
     | 
| 
      
 9 
     | 
    
         
            +
            class MappedErrorTest < Test::Unit::TestCase
         
     | 
| 
      
 10 
     | 
    
         
            +
              def test_default
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert true
         
     | 
| 
       35 
12 
     | 
    
         
             
              end
         
     | 
| 
       36 
13 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
                 
     | 
| 
       39 
     | 
    
         
            -
                   
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                     
     | 
| 
       42 
     | 
    
         
            -
                     
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe 'Exception Mappings' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                it 'invokes handlers registered with ::error when raised' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 17 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 18 
     | 
    
         
            +
                    error(FooError) { 'Foo!' }
         
     | 
| 
      
 19 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  }
         
     | 
| 
      
 23 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 24 
     | 
    
         
            +
                  assert_equal 500, status
         
     | 
| 
      
 25 
     | 
    
         
            +
                  assert_equal 'Foo!', body
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                it 'uses the Exception handler if no matching handler found' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 31 
     | 
    
         
            +
                    error(Exception) { 'Exception!' }
         
     | 
| 
      
 32 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
       44 
35 
     | 
    
         
             
                  }
         
     | 
| 
       45 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       46 
     | 
    
         
            -
                    raise FooError
         
     | 
| 
       47 
     | 
    
         
            -
                  end
         
     | 
| 
       48 
     | 
    
         
            -
                }
         
     | 
| 
       49 
     | 
    
         
            -
                get '/'
         
     | 
| 
       50 
     | 
    
         
            -
                body.should.equal 'looks good'
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              it 'dumps errors to rack.errors when dump_errors is enabled' do
         
     | 
| 
       54 
     | 
    
         
            -
                mock_app {
         
     | 
| 
       55 
     | 
    
         
            -
                  set :raise_errors, false
         
     | 
| 
       56 
     | 
    
         
            -
                  set :dump_errors, true
         
     | 
| 
       57 
     | 
    
         
            -
                  get('/') { raise FooError, 'BOOM!' }
         
     | 
| 
       58 
     | 
    
         
            -
                }
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                get '/'
         
     | 
| 
       61 
     | 
    
         
            -
                status.should.equal 500
         
     | 
| 
       62 
     | 
    
         
            -
                @response.errors.should.match(/FooError - BOOM!:/)
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              it "raises without calling the handler when the raise_errors options is set" do
         
     | 
| 
       66 
     | 
    
         
            -
                mock_app {
         
     | 
| 
       67 
     | 
    
         
            -
                  set :raise_errors, true
         
     | 
| 
       68 
     | 
    
         
            -
                  error(FooError) { "she's not there." }
         
     | 
| 
       69 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       70 
     | 
    
         
            -
                    raise FooError
         
     | 
| 
       71 
     | 
    
         
            -
                  end
         
     | 
| 
       72 
     | 
    
         
            -
                }
         
     | 
| 
       73 
     | 
    
         
            -
                lambda { get '/' }.should.raise FooError
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
36 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                   
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 38 
     | 
    
         
            +
                  assert_equal 500, status
         
     | 
| 
      
 39 
     | 
    
         
            +
                  assert_equal 'Exception!', body
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                it "sets env['sinatra.error'] to the rescued exception" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 44 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 45 
     | 
    
         
            +
                    error(FooError) {
         
     | 
| 
      
 46 
     | 
    
         
            +
                      assert env.include?('sinatra.error')
         
     | 
| 
      
 47 
     | 
    
         
            +
                      assert env['sinatra.error'].kind_of?(FooError)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      'looks good'
         
     | 
| 
      
 49 
     | 
    
         
            +
                    }
         
     | 
| 
      
 50 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  }
         
     | 
| 
      
 54 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 55 
     | 
    
         
            +
                  assert_equal 'looks good', body
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                it "raises without calling the handler when the raise_errors options is set" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 60 
     | 
    
         
            +
                    set :raise_errors, true
         
     | 
| 
      
 61 
     | 
    
         
            +
                    error(FooError) { "she's not there." }
         
     | 
| 
      
 62 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  }
         
     | 
| 
      
 66 
     | 
    
         
            +
                  assert_raise(FooError) { get '/' }
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                it "never raises Sinatra::NotFound beyond the application" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 71 
     | 
    
         
            +
                    set :raise_errors, true
         
     | 
| 
      
 72 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 73 
     | 
    
         
            +
                      raise Sinatra::NotFound
         
     | 
| 
      
 74 
     | 
    
         
            +
                    end
         
     | 
| 
      
 75 
     | 
    
         
            +
                  }
         
     | 
| 
      
 76 
     | 
    
         
            +
                  assert_nothing_raised { get '/' }
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_equal 404, status
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it "cascades for subclasses of Sinatra::NotFound" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 82 
     | 
    
         
            +
                    set :raise_errors, true
         
     | 
| 
      
 83 
     | 
    
         
            +
                    error(FooNotFound) { "foo! not found." }
         
     | 
| 
      
 84 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 85 
     | 
    
         
            +
                      raise FooNotFound
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
                  }
         
     | 
| 
      
 88 
     | 
    
         
            +
                  assert_nothing_raised { get '/' }
         
     | 
| 
      
 89 
     | 
    
         
            +
                  assert_equal 404, status
         
     | 
| 
      
 90 
     | 
    
         
            +
                  assert_equal 'foo! not found.', body
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                it 'has a not_found method for backwards compatibility' do
         
     | 
| 
      
 94 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 95 
     | 
    
         
            +
                    not_found do
         
     | 
| 
      
 96 
     | 
    
         
            +
                      "Lost, are we?"
         
     | 
| 
      
 97 
     | 
    
         
            +
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
                  }
         
     | 
| 
       86 
99 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
      
 100 
     | 
    
         
            +
                  get '/test'
         
     | 
| 
      
 101 
     | 
    
         
            +
                  assert_equal 404, status
         
     | 
| 
      
 102 
     | 
    
         
            +
                  assert_equal "Lost, are we?", body
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
       89 
104 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                   
     | 
| 
       93 
     | 
    
         
            -
                  error(FooNotFound) { "foo! not found." }
         
     | 
| 
       94 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       95 
     | 
    
         
            -
                    raise FooNotFound
         
     | 
| 
       96 
     | 
    
         
            -
                  end
         
     | 
| 
       97 
     | 
    
         
            -
                }
         
     | 
| 
       98 
     | 
    
         
            -
                lambda { get '/' }.should.not.raise FooNotFound
         
     | 
| 
       99 
     | 
    
         
            -
                status.should.equal 404
         
     | 
| 
       100 
     | 
    
         
            -
                body.should.equal 'foo! not found.'
         
     | 
| 
       101 
     | 
    
         
            -
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
                it 'inherits error mappings from base class' do
         
     | 
| 
      
 106 
     | 
    
         
            +
                  base = Class.new(Sinatra::Base)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  base.error(FooError) { 'base class' }
         
     | 
| 
       102 
108 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
      
 109 
     | 
    
         
            +
                  mock_app(base) {
         
     | 
| 
      
 110 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 111 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 112 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 113 
     | 
    
         
            +
                    end
         
     | 
| 
      
 114 
     | 
    
         
            +
                  }
         
     | 
| 
       109 
115 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                 
     | 
| 
       113 
     | 
    
         
            -
              end
         
     | 
| 
       114 
     | 
    
         
            -
            end
         
     | 
| 
      
 116 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 117 
     | 
    
         
            +
                  assert_equal 'base class', body
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
       115 
119 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                  set :raise_errors, false
         
     | 
| 
       120 
     | 
    
         
            -
                  error(500) { 'Foo!' }
         
     | 
| 
       121 
     | 
    
         
            -
                  get '/' do
         
     | 
| 
       122 
     | 
    
         
            -
                    [500, {}, 'Internal Foo Error']
         
     | 
| 
       123 
     | 
    
         
            -
                  end
         
     | 
| 
       124 
     | 
    
         
            -
                }
         
     | 
| 
       125 
     | 
    
         
            -
                get '/'
         
     | 
| 
       126 
     | 
    
         
            -
                status.should.equal 500
         
     | 
| 
       127 
     | 
    
         
            -
                body.should.equal 'Foo!'
         
     | 
| 
       128 
     | 
    
         
            -
              end
         
     | 
| 
      
 120 
     | 
    
         
            +
                it 'overrides error mappings in base class' do
         
     | 
| 
      
 121 
     | 
    
         
            +
                  base = Class.new(Sinatra::Base)
         
     | 
| 
      
 122 
     | 
    
         
            +
                  base.error(FooError) { 'base class' }
         
     | 
| 
       129 
123 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                     
     | 
| 
       136 
     | 
    
         
            -
                   
     | 
| 
       137 
     | 
    
         
            -
                }
         
     | 
| 
       138 
     | 
    
         
            -
                get '/'
         
     | 
| 
       139 
     | 
    
         
            -
                status.should.equal 507
         
     | 
| 
       140 
     | 
    
         
            -
                body.should.equal 'Error: 507'
         
     | 
| 
       141 
     | 
    
         
            -
              end
         
     | 
| 
      
 124 
     | 
    
         
            +
                  mock_app(base) {
         
     | 
| 
      
 125 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 126 
     | 
    
         
            +
                    error(FooError) { 'subclass' }
         
     | 
| 
      
 127 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 128 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 129 
     | 
    
         
            +
                    end
         
     | 
| 
      
 130 
     | 
    
         
            +
                  }
         
     | 
| 
       142 
131 
     | 
    
         | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
      
 132 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 133 
     | 
    
         
            +
                  assert_equal 'subclass', body
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
       144 
135 
     | 
    
         
             
              end
         
     | 
| 
       145 
136 
     | 
    
         | 
| 
       146 
     | 
    
         
            -
               
     | 
| 
       147 
     | 
    
         
            -
                 
     | 
| 
       148 
     | 
    
         
            -
                   
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
                     
     | 
| 
       151 
     | 
    
         
            -
                    ' 
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
                   
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
                   
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                 
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
      
 137 
     | 
    
         
            +
              describe 'Custom Error Pages' do
         
     | 
| 
      
 138 
     | 
    
         
            +
                it 'allows numeric status code mappings to be registered with ::error' do
         
     | 
| 
      
 139 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 140 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 141 
     | 
    
         
            +
                    error(500) { 'Foo!' }
         
     | 
| 
      
 142 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 143 
     | 
    
         
            +
                      [500, {}, 'Internal Foo Error']
         
     | 
| 
      
 144 
     | 
    
         
            +
                    end
         
     | 
| 
      
 145 
     | 
    
         
            +
                  }
         
     | 
| 
      
 146 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 147 
     | 
    
         
            +
                  assert_equal 500, status
         
     | 
| 
      
 148 
     | 
    
         
            +
                  assert_equal 'Foo!', body
         
     | 
| 
      
 149 
     | 
    
         
            +
                end
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                it 'allows ranges of status code mappings to be registered with :error' do
         
     | 
| 
      
 152 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 153 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 154 
     | 
    
         
            +
                    error(500..550) { "Error: #{response.status}" }
         
     | 
| 
      
 155 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 156 
     | 
    
         
            +
                      [507, {}, 'A very special error']
         
     | 
| 
      
 157 
     | 
    
         
            +
                    end
         
     | 
| 
      
 158 
     | 
    
         
            +
                  }
         
     | 
| 
      
 159 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 160 
     | 
    
         
            +
                  assert_equal 507, status
         
     | 
| 
      
 161 
     | 
    
         
            +
                  assert_equal 'Error: 507', body
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                class FooError < RuntimeError
         
     | 
| 
      
 165 
     | 
    
         
            +
                end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                it 'runs after exception mappings and overwrites body' do
         
     | 
| 
      
 168 
     | 
    
         
            +
                  mock_app {
         
     | 
| 
      
 169 
     | 
    
         
            +
                    set :raise_errors, false
         
     | 
| 
      
 170 
     | 
    
         
            +
                    error FooError do
         
     | 
| 
      
 171 
     | 
    
         
            +
                      response.status = 502
         
     | 
| 
      
 172 
     | 
    
         
            +
                      'from exception mapping'
         
     | 
| 
      
 173 
     | 
    
         
            +
                    end
         
     | 
| 
      
 174 
     | 
    
         
            +
                    error(500) { 'from 500 handler' }
         
     | 
| 
      
 175 
     | 
    
         
            +
                    error(502) { 'from custom error page' }
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 178 
     | 
    
         
            +
                      raise FooError
         
     | 
| 
      
 179 
     | 
    
         
            +
                    end
         
     | 
| 
      
 180 
     | 
    
         
            +
                  }
         
     | 
| 
      
 181 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 182 
     | 
    
         
            +
                  assert_equal 502, status
         
     | 
| 
      
 183 
     | 
    
         
            +
                  assert_equal 'from custom error page', body
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
       163 
185 
     | 
    
         
             
              end
         
     | 
| 
       164 
186 
     | 
    
         
             
            end
         
     | 
    
        data/test/middleware_test.rb
    CHANGED
    
    | 
         @@ -1,14 +1,12 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require ' 
     | 
| 
       2 
     | 
    
         
            -
            require 'sinatra/base'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'sinatra/test'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/helper'
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              before do
         
     | 
| 
      
 3 
     | 
    
         
            +
            class MiddlewareTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              setup do
         
     | 
| 
       9 
5 
     | 
    
         
             
                @app = mock_app(Sinatra::Default) {
         
     | 
| 
       10 
6 
     | 
    
         
             
                  get '/*' do
         
     | 
| 
       11 
     | 
    
         
            -
                    response.headers['X-Tests'] = env['test.ran']. 
     | 
| 
      
 7 
     | 
    
         
            +
                    response.headers['X-Tests'] = env['test.ran'].
         
     | 
| 
      
 8 
     | 
    
         
            +
                      map { |n| n.split('::').last }.
         
     | 
| 
      
 9 
     | 
    
         
            +
                      join(', ')
         
     | 
| 
       12 
10 
     | 
    
         
             
                    env['PATH_INFO']
         
     | 
| 
       13 
11 
     | 
    
         
             
                  end
         
     | 
| 
       14 
12 
     | 
    
         
             
                }
         
     | 
| 
         @@ -31,8 +29,8 @@ describe "Middleware" do 
     | 
|
| 
       31 
29 
     | 
    
         
             
              it "is added with Sinatra::Application.use" do
         
     | 
| 
       32 
30 
     | 
    
         
             
                @app.use UpcaseMiddleware
         
     | 
| 
       33 
31 
     | 
    
         
             
                get '/hello-world'
         
     | 
| 
       34 
     | 
    
         
            -
                 
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
                assert ok?
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal '/HELLO-WORLD', body
         
     | 
| 
       36 
34 
     | 
    
         
             
              end
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
36 
     | 
    
         
             
              class DowncaseMiddleware < MockMiddleware
         
     | 
| 
         @@ -42,22 +40,29 @@ describe "Middleware" do 
     | 
|
| 
       42 
40 
     | 
    
         
             
                end
         
     | 
| 
       43 
41 
     | 
    
         
             
              end
         
     | 
| 
       44 
42 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
               
     | 
| 
      
 43 
     | 
    
         
            +
              it "runs in the order defined" do
         
     | 
| 
       46 
44 
     | 
    
         
             
                @app.use UpcaseMiddleware
         
     | 
| 
       47 
45 
     | 
    
         
             
                @app.use DowncaseMiddleware
         
     | 
| 
       48 
46 
     | 
    
         
             
                get '/Foo'
         
     | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
                response['X-Tests'] 
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal "/foo", body
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
         
     | 
| 
       51 
49 
     | 
    
         
             
              end
         
     | 
| 
       52 
50 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
               
     | 
| 
      
 51 
     | 
    
         
            +
              it "resets the prebuilt pipeline when new middleware is added" do
         
     | 
| 
       54 
52 
     | 
    
         
             
                @app.use UpcaseMiddleware
         
     | 
| 
       55 
53 
     | 
    
         
             
                get '/Foo'
         
     | 
| 
       56 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
                assert_equal "/FOO", body
         
     | 
| 
       57 
55 
     | 
    
         
             
                @app.use DowncaseMiddleware
         
     | 
| 
       58 
56 
     | 
    
         
             
                get '/Foo'
         
     | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
       60 
     | 
    
         
            -
                response['X-Tests'] 
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal '/foo', body
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
         
     | 
| 
       61 
59 
     | 
    
         
             
              end
         
     | 
| 
       62 
60 
     | 
    
         | 
| 
      
 61 
     | 
    
         
            +
              it "works when app is used as middleware" do
         
     | 
| 
      
 62 
     | 
    
         
            +
                @app.use UpcaseMiddleware
         
     | 
| 
      
 63 
     | 
    
         
            +
                @app = @app.new
         
     | 
| 
      
 64 
     | 
    
         
            +
                get '/Foo'
         
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal "/FOO", body
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal "UpcaseMiddleware", response['X-Tests']
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
       63 
68 
     | 
    
         
             
            end
         
     | 
    
        data/test/options_test.rb
    CHANGED
    
    | 
         @@ -1,72 +1,71 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require ' 
     | 
| 
       2 
     | 
    
         
            -
            require 'sinatra/base'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'sinatra/test'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/helper'
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                @ 
     | 
| 
      
 3 
     | 
    
         
            +
            class OptionsTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              setup do
         
     | 
| 
      
 5 
     | 
    
         
            +
                @base    = Sinatra.new(Sinatra::Base)
         
     | 
| 
      
 6 
     | 
    
         
            +
                @default = Sinatra.new(Sinatra::Default)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @base.set    :environment, :development
         
     | 
| 
      
 8 
     | 
    
         
            +
                @default.set :environment, :development
         
     | 
| 
       10 
9 
     | 
    
         
             
              end
         
     | 
| 
       11 
10 
     | 
    
         | 
| 
       12 
11 
     | 
    
         
             
              it 'sets options to literal values' do
         
     | 
| 
       13 
     | 
    
         
            -
                @ 
     | 
| 
       14 
     | 
    
         
            -
                @ 
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
                @base.set(:foo, 'bar')
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert @base.respond_to?(:foo)
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert_equal 'bar', @base.foo
         
     | 
| 
       16 
15 
     | 
    
         
             
              end
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
17 
     | 
    
         
             
              it 'sets options to Procs' do
         
     | 
| 
       19 
     | 
    
         
            -
                @ 
     | 
| 
       20 
     | 
    
         
            -
                @ 
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
      
 18 
     | 
    
         
            +
                @base.set(:foo, Proc.new { 'baz' })
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert @base.respond_to?(:foo)
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal 'baz', @base.foo
         
     | 
| 
       22 
21 
     | 
    
         
             
              end
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
23 
     | 
    
         
             
              it "sets multiple options with a Hash" do
         
     | 
| 
       25 
     | 
    
         
            -
                @ 
     | 
| 
      
 24 
     | 
    
         
            +
                @base.set :foo => 1234,
         
     | 
| 
       26 
25 
     | 
    
         
             
                    :bar => 'Hello World',
         
     | 
| 
       27 
26 
     | 
    
         
             
                    :baz => Proc.new { 'bizzle' }
         
     | 
| 
       28 
     | 
    
         
            -
                @ 
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal 1234, @base.foo
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal 'Hello World', @base.bar
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal 'bizzle', @base.baz
         
     | 
| 
       31 
30 
     | 
    
         
             
              end
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
       33 
32 
     | 
    
         
             
              it 'inherits option methods when subclassed' do
         
     | 
| 
       34 
     | 
    
         
            -
                @ 
     | 
| 
       35 
     | 
    
         
            -
                @ 
     | 
| 
      
 33 
     | 
    
         
            +
                @base.set :foo, 'bar'
         
     | 
| 
      
 34 
     | 
    
         
            +
                @base.set :biz, Proc.new { 'baz' }
         
     | 
| 
       36 
35 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                sub = Class.new(@ 
     | 
| 
       38 
     | 
    
         
            -
                sub. 
     | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
       40 
     | 
    
         
            -
                sub. 
     | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
      
 36 
     | 
    
         
            +
                sub = Class.new(@base)
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert sub.respond_to?(:foo)
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal 'bar', sub.foo
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert sub.respond_to?(:biz)
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal 'baz', sub.biz
         
     | 
| 
       42 
41 
     | 
    
         
             
              end
         
     | 
| 
       43 
42 
     | 
    
         | 
| 
       44 
43 
     | 
    
         
             
              it 'overrides options in subclass' do
         
     | 
| 
       45 
     | 
    
         
            -
                @ 
     | 
| 
       46 
     | 
    
         
            -
                @ 
     | 
| 
       47 
     | 
    
         
            -
                sub = Class.new(@ 
     | 
| 
      
 44 
     | 
    
         
            +
                @base.set :foo, 'bar'
         
     | 
| 
      
 45 
     | 
    
         
            +
                @base.set :biz, Proc.new { 'baz' }
         
     | 
| 
      
 46 
     | 
    
         
            +
                sub = Class.new(@base)
         
     | 
| 
       48 
47 
     | 
    
         
             
                sub.set :foo, 'bling'
         
     | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
                 
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal 'bling', sub.foo
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal 'bar', @base.foo
         
     | 
| 
       51 
50 
     | 
    
         
             
              end
         
     | 
| 
       52 
51 
     | 
    
         | 
| 
       53 
52 
     | 
    
         
             
              it 'creates setter methods when first defined' do
         
     | 
| 
       54 
     | 
    
         
            -
                @ 
     | 
| 
       55 
     | 
    
         
            -
                @ 
     | 
| 
       56 
     | 
    
         
            -
                @ 
     | 
| 
       57 
     | 
    
         
            -
                 
     | 
| 
      
 53 
     | 
    
         
            +
                @base.set :foo, 'bar'
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert @base.respond_to?('foo=')
         
     | 
| 
      
 55 
     | 
    
         
            +
                @base.foo = 'biz'
         
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal 'biz', @base.foo
         
     | 
| 
       58 
57 
     | 
    
         
             
              end
         
     | 
| 
       59 
58 
     | 
    
         | 
| 
       60 
59 
     | 
    
         
             
              it 'creates predicate methods when first defined' do
         
     | 
| 
       61 
     | 
    
         
            -
                @ 
     | 
| 
       62 
     | 
    
         
            -
                @ 
     | 
| 
       63 
     | 
    
         
            -
                @ 
     | 
| 
       64 
     | 
    
         
            -
                @ 
     | 
| 
       65 
     | 
    
         
            -
                 
     | 
| 
      
 60 
     | 
    
         
            +
                @base.set :foo, 'hello world'
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert @base.respond_to?(:foo?)
         
     | 
| 
      
 62 
     | 
    
         
            +
                assert @base.foo?
         
     | 
| 
      
 63 
     | 
    
         
            +
                @base.set :foo, nil
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert !@base.foo?
         
     | 
| 
       66 
65 
     | 
    
         
             
              end
         
     | 
| 
       67 
66 
     | 
    
         | 
| 
       68 
67 
     | 
    
         
             
              it 'uses existing setter methods if detected' do
         
     | 
| 
       69 
     | 
    
         
            -
                class << @ 
     | 
| 
      
 68 
     | 
    
         
            +
                class << @base
         
     | 
| 
       70 
69 
     | 
    
         
             
                  def foo
         
     | 
| 
       71 
70 
     | 
    
         
             
                    @foo
         
     | 
| 
       72 
71 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -75,29 +74,299 @@ describe 'Options' do 
     | 
|
| 
       75 
74 
     | 
    
         
             
                  end
         
     | 
| 
       76 
75 
     | 
    
         
             
                end
         
     | 
| 
       77 
76 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
                @ 
     | 
| 
       79 
     | 
    
         
            -
                 
     | 
| 
      
 77 
     | 
    
         
            +
                @base.set :foo, 'bam'
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal 'oops', @base.foo
         
     | 
| 
       80 
79 
     | 
    
         
             
              end
         
     | 
| 
       81 
80 
     | 
    
         | 
| 
       82 
81 
     | 
    
         
             
              it "sets multiple options to true with #enable" do
         
     | 
| 
       83 
     | 
    
         
            -
                @ 
     | 
| 
       84 
     | 
    
         
            -
                @ 
     | 
| 
       85 
     | 
    
         
            -
                @ 
     | 
| 
       86 
     | 
    
         
            -
                @ 
     | 
| 
      
 82 
     | 
    
         
            +
                @base.enable :sessions, :foo, :bar
         
     | 
| 
      
 83 
     | 
    
         
            +
                assert @base.sessions
         
     | 
| 
      
 84 
     | 
    
         
            +
                assert @base.foo
         
     | 
| 
      
 85 
     | 
    
         
            +
                assert @base.bar
         
     | 
| 
       87 
86 
     | 
    
         
             
              end
         
     | 
| 
       88 
87 
     | 
    
         | 
| 
       89 
88 
     | 
    
         
             
              it "sets multiple options to false with #disable" do
         
     | 
| 
       90 
     | 
    
         
            -
                @ 
     | 
| 
       91 
     | 
    
         
            -
                 
     | 
| 
       92 
     | 
    
         
            -
                 
     | 
| 
       93 
     | 
    
         
            -
                 
     | 
| 
      
 89 
     | 
    
         
            +
                @base.disable :sessions, :foo, :bar
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert !@base.sessions
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert !@base.foo
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert !@base.bar
         
     | 
| 
       94 
93 
     | 
    
         
             
              end
         
     | 
| 
       95 
94 
     | 
    
         | 
| 
       96 
95 
     | 
    
         
             
              it 'enables MethodOverride middleware when :methodoverride is enabled' do
         
     | 
| 
       97 
     | 
    
         
            -
                @ 
     | 
| 
       98 
     | 
    
         
            -
                @ 
     | 
| 
      
 96 
     | 
    
         
            +
                @base.set :methodoverride, true
         
     | 
| 
      
 97 
     | 
    
         
            +
                @base.put('/') { 'okay' }
         
     | 
| 
      
 98 
     | 
    
         
            +
                @app = @base
         
     | 
| 
       99 
99 
     | 
    
         
             
                post '/', {'_method'=>'PUT'}, {}
         
     | 
| 
       100 
     | 
    
         
            -
                 
     | 
| 
       101 
     | 
    
         
            -
                 
     | 
| 
      
 100 
     | 
    
         
            +
                assert_equal 200, status
         
     | 
| 
      
 101 
     | 
    
         
            +
                assert_equal 'okay', body
         
     | 
| 
      
 102 
     | 
    
         
            +
              end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
              describe 'clean_trace' do
         
     | 
| 
      
 105 
     | 
    
         
            +
                def clean_backtrace(trace)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  Sinatra::Base.new.send(:clean_backtrace, trace)
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                it 'is enabled on Base' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                  assert @base.clean_trace?
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                it 'is enabled on Default' do
         
     | 
| 
      
 114 
     | 
    
         
            +
                  assert @default.clean_trace?
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                it 'does nothing when disabled' do
         
     | 
| 
      
 118 
     | 
    
         
            +
                  backtrace = [
         
     | 
| 
      
 119 
     | 
    
         
            +
                    "./lib/sinatra/base.rb",
         
     | 
| 
      
 120 
     | 
    
         
            +
                    "./myapp:42",
         
     | 
| 
      
 121 
     | 
    
         
            +
                    ("#{Gem.dir}/some/lib.rb" if defined?(Gem))
         
     | 
| 
      
 122 
     | 
    
         
            +
                  ].compact
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                  klass = Class.new(Sinatra::Base)
         
     | 
| 
      
 125 
     | 
    
         
            +
                  klass.disable :clean_trace
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                  assert_equal backtrace, klass.new.send(:clean_backtrace, backtrace)
         
     | 
| 
      
 128 
     | 
    
         
            +
                end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                it 'removes sinatra lib paths from backtrace when enabled' do
         
     | 
| 
      
 131 
     | 
    
         
            +
                  backtrace = [
         
     | 
| 
      
 132 
     | 
    
         
            +
                    "./lib/sinatra/base.rb",
         
     | 
| 
      
 133 
     | 
    
         
            +
                    "./lib/sinatra/compat.rb:42",
         
     | 
| 
      
 134 
     | 
    
         
            +
                    "./lib/sinatra/main.rb:55 in `foo'"
         
     | 
| 
      
 135 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 136 
     | 
    
         
            +
                  assert clean_backtrace(backtrace).empty?
         
     | 
| 
      
 137 
     | 
    
         
            +
                end
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                it 'removes ./ prefix from backtrace paths when enabled' do
         
     | 
| 
      
 140 
     | 
    
         
            +
                  assert_equal ['myapp.rb:42'], clean_backtrace(['./myapp.rb:42'])
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                if defined?(Gem)
         
     | 
| 
      
 144 
     | 
    
         
            +
                  it 'removes gem lib paths from backtrace when enabled' do
         
     | 
| 
      
 145 
     | 
    
         
            +
                    assert clean_backtrace(["#{Gem.dir}/some/lib"]).empty?
         
     | 
| 
      
 146 
     | 
    
         
            +
                  end
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
              describe 'run' do
         
     | 
| 
      
 151 
     | 
    
         
            +
                it 'is disabled on Base' do
         
     | 
| 
      
 152 
     | 
    
         
            +
                  assert ! @base.run?
         
     | 
| 
      
 153 
     | 
    
         
            +
                end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                it 'is enabled on Default when not in test environment' do
         
     | 
| 
      
 156 
     | 
    
         
            +
                  @default.set :environment, :development
         
     | 
| 
      
 157 
     | 
    
         
            +
                  assert @default.development?
         
     | 
| 
      
 158 
     | 
    
         
            +
                  assert @default.run?
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                  @default.set :environment, :development
         
     | 
| 
      
 161 
     | 
    
         
            +
                  assert @default.run?
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                # TODO: it 'is enabled when $0 == app_file'
         
     | 
| 
      
 165 
     | 
    
         
            +
              end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
              describe 'raise_errors' do
         
     | 
| 
      
 168 
     | 
    
         
            +
                it 'is enabled on Base' do
         
     | 
| 
      
 169 
     | 
    
         
            +
                  assert @base.raise_errors?
         
     | 
| 
      
 170 
     | 
    
         
            +
                end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                it 'is enabled on Default only in test' do
         
     | 
| 
      
 173 
     | 
    
         
            +
                  @default.set(:environment, :development)
         
     | 
| 
      
 174 
     | 
    
         
            +
                  assert @default.development?
         
     | 
| 
      
 175 
     | 
    
         
            +
                  assert ! @default.raise_errors?
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  @default.set(:environment, :production)
         
     | 
| 
      
 178 
     | 
    
         
            +
                  assert ! @default.raise_errors?
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                  @default.set(:environment, :test)
         
     | 
| 
      
 181 
     | 
    
         
            +
                  assert @default.raise_errors?
         
     | 
| 
      
 182 
     | 
    
         
            +
                end
         
     | 
| 
      
 183 
     | 
    
         
            +
              end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
              describe 'show_exceptions' do
         
     | 
| 
      
 186 
     | 
    
         
            +
                %w[development test production none].each do |environment|
         
     | 
| 
      
 187 
     | 
    
         
            +
                  it "is disabled on Base in #{environment} environments" do
         
     | 
| 
      
 188 
     | 
    
         
            +
                    @base.set(:environment, environment)
         
     | 
| 
      
 189 
     | 
    
         
            +
                    assert ! @base.show_exceptions?
         
     | 
| 
      
 190 
     | 
    
         
            +
                  end
         
     | 
| 
      
 191 
     | 
    
         
            +
                end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                it 'is enabled on Default only in development' do
         
     | 
| 
      
 194 
     | 
    
         
            +
                  @base.set(:environment, :development)
         
     | 
| 
      
 195 
     | 
    
         
            +
                  assert @default.development?
         
     | 
| 
      
 196 
     | 
    
         
            +
                  assert @default.show_exceptions?
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                  @default.set(:environment, :test)
         
     | 
| 
      
 199 
     | 
    
         
            +
                  assert ! @default.show_exceptions?
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                  @base.set(:environment, :production)
         
     | 
| 
      
 202 
     | 
    
         
            +
                  assert ! @base.show_exceptions?
         
     | 
| 
      
 203 
     | 
    
         
            +
                end
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
                it 'returns a friendly 500' do
         
     | 
| 
      
 206 
     | 
    
         
            +
                  klass = Sinatra.new(Sinatra::Default)
         
     | 
| 
      
 207 
     | 
    
         
            +
                  mock_app(klass) {
         
     | 
| 
      
 208 
     | 
    
         
            +
                    enable :show_exceptions
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 211 
     | 
    
         
            +
                      raise StandardError
         
     | 
| 
      
 212 
     | 
    
         
            +
                    end
         
     | 
| 
      
 213 
     | 
    
         
            +
                  }
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 216 
     | 
    
         
            +
                  assert_equal 500, status
         
     | 
| 
      
 217 
     | 
    
         
            +
                  assert body.include?("StandardError")
         
     | 
| 
      
 218 
     | 
    
         
            +
                  assert body.include?("<code>show_exceptions</code> option")
         
     | 
| 
      
 219 
     | 
    
         
            +
                end
         
     | 
| 
      
 220 
     | 
    
         
            +
              end
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
              describe 'dump_errors' do
         
     | 
| 
      
 223 
     | 
    
         
            +
                it 'is disabled on Base' do
         
     | 
| 
      
 224 
     | 
    
         
            +
                  assert ! @base.dump_errors?
         
     | 
| 
      
 225 
     | 
    
         
            +
                end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                it 'is enabled on Default' do
         
     | 
| 
      
 228 
     | 
    
         
            +
                  assert @default.dump_errors?
         
     | 
| 
      
 229 
     | 
    
         
            +
                end
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
                it 'dumps exception with backtrace to rack.errors' do
         
     | 
| 
      
 232 
     | 
    
         
            +
                  klass = Sinatra.new(Sinatra::Default)
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                  mock_app(klass) {
         
     | 
| 
      
 235 
     | 
    
         
            +
                    disable :raise_errors
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
                    error do
         
     | 
| 
      
 238 
     | 
    
         
            +
                      error = @env['rack.errors'].instance_variable_get(:@error)
         
     | 
| 
      
 239 
     | 
    
         
            +
                      error.rewind
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
      
 241 
     | 
    
         
            +
                      error.read
         
     | 
| 
      
 242 
     | 
    
         
            +
                    end
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
                    get '/' do
         
     | 
| 
      
 245 
     | 
    
         
            +
                      raise
         
     | 
| 
      
 246 
     | 
    
         
            +
                    end
         
     | 
| 
      
 247 
     | 
    
         
            +
                  }
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
                  get '/'
         
     | 
| 
      
 250 
     | 
    
         
            +
                  assert body.include?("RuntimeError") && body.include?("options_test.rb")
         
     | 
| 
      
 251 
     | 
    
         
            +
                end
         
     | 
| 
      
 252 
     | 
    
         
            +
              end
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
              describe 'sessions' do
         
     | 
| 
      
 255 
     | 
    
         
            +
                it 'is disabled on Base' do
         
     | 
| 
      
 256 
     | 
    
         
            +
                  assert ! @base.sessions?
         
     | 
| 
      
 257 
     | 
    
         
            +
                end
         
     | 
| 
      
 258 
     | 
    
         
            +
             
     | 
| 
      
 259 
     | 
    
         
            +
                it 'is disabled on Default' do
         
     | 
| 
      
 260 
     | 
    
         
            +
                  assert ! @default.sessions?
         
     | 
| 
      
 261 
     | 
    
         
            +
                end
         
     | 
| 
      
 262 
     | 
    
         
            +
             
     | 
| 
      
 263 
     | 
    
         
            +
                # TODO: it 'uses Rack::Session::Cookie when enabled' do
         
     | 
| 
      
 264 
     | 
    
         
            +
              end
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
              describe 'logging' do
         
     | 
| 
      
 267 
     | 
    
         
            +
                it 'is disabled on Base' do
         
     | 
| 
      
 268 
     | 
    
         
            +
                  assert ! @base.logging?
         
     | 
| 
      
 269 
     | 
    
         
            +
                end
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
                it 'is enabled on Default when not in test environment' do
         
     | 
| 
      
 272 
     | 
    
         
            +
                  assert @default.logging?
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
                  @default.set :environment, :test
         
     | 
| 
      
 275 
     | 
    
         
            +
                  assert ! @default.logging
         
     | 
| 
      
 276 
     | 
    
         
            +
                end
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
                # TODO: it 'uses Rack::CommonLogger when enabled' do
         
     | 
| 
      
 279 
     | 
    
         
            +
              end
         
     | 
| 
      
 280 
     | 
    
         
            +
             
     | 
| 
      
 281 
     | 
    
         
            +
              describe 'static' do
         
     | 
| 
      
 282 
     | 
    
         
            +
                it 'is disabled on Base' do
         
     | 
| 
      
 283 
     | 
    
         
            +
                  assert ! @base.static?
         
     | 
| 
      
 284 
     | 
    
         
            +
                end
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
                it 'is enabled on Default' do
         
     | 
| 
      
 287 
     | 
    
         
            +
                  assert @default.static?
         
     | 
| 
      
 288 
     | 
    
         
            +
                end
         
     | 
| 
      
 289 
     | 
    
         
            +
             
     | 
| 
      
 290 
     | 
    
         
            +
                # TODO: it setup static routes if public is enabled
         
     | 
| 
      
 291 
     | 
    
         
            +
                # TODO: however, that's already tested in static_test so...
         
     | 
| 
      
 292 
     | 
    
         
            +
              end
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
              describe 'host' do
         
     | 
| 
      
 295 
     | 
    
         
            +
                it 'defaults to 0.0.0.0' do
         
     | 
| 
      
 296 
     | 
    
         
            +
                  assert_equal '0.0.0.0', @base.host
         
     | 
| 
      
 297 
     | 
    
         
            +
                  assert_equal '0.0.0.0', @default.host
         
     | 
| 
      
 298 
     | 
    
         
            +
                end
         
     | 
| 
      
 299 
     | 
    
         
            +
              end
         
     | 
| 
      
 300 
     | 
    
         
            +
             
     | 
| 
      
 301 
     | 
    
         
            +
              describe 'port' do
         
     | 
| 
      
 302 
     | 
    
         
            +
                it 'defaults to 4567' do
         
     | 
| 
      
 303 
     | 
    
         
            +
                  assert_equal 4567, @base.port
         
     | 
| 
      
 304 
     | 
    
         
            +
                  assert_equal 4567, @default.port
         
     | 
| 
      
 305 
     | 
    
         
            +
                end
         
     | 
| 
      
 306 
     | 
    
         
            +
              end
         
     | 
| 
      
 307 
     | 
    
         
            +
             
     | 
| 
      
 308 
     | 
    
         
            +
              describe 'server' do
         
     | 
| 
      
 309 
     | 
    
         
            +
                it 'is one of thin, mongrel, webrick' do
         
     | 
| 
      
 310 
     | 
    
         
            +
                  assert_equal %w[thin mongrel webrick], @base.server
         
     | 
| 
      
 311 
     | 
    
         
            +
                  assert_equal %w[thin mongrel webrick], @default.server
         
     | 
| 
      
 312 
     | 
    
         
            +
                end
         
     | 
| 
      
 313 
     | 
    
         
            +
              end
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
              describe 'app_file' do
         
     | 
| 
      
 316 
     | 
    
         
            +
                it 'is nil' do
         
     | 
| 
      
 317 
     | 
    
         
            +
                  assert @base.app_file.nil?
         
     | 
| 
      
 318 
     | 
    
         
            +
                  assert @default.app_file.nil?
         
     | 
| 
      
 319 
     | 
    
         
            +
                end
         
     | 
| 
      
 320 
     | 
    
         
            +
              end
         
     | 
| 
      
 321 
     | 
    
         
            +
             
     | 
| 
      
 322 
     | 
    
         
            +
              describe 'root' do
         
     | 
| 
      
 323 
     | 
    
         
            +
                it 'is nil if app_file is not set' do
         
     | 
| 
      
 324 
     | 
    
         
            +
                  assert @base.root.nil?
         
     | 
| 
      
 325 
     | 
    
         
            +
                  assert @default.root.nil?
         
     | 
| 
      
 326 
     | 
    
         
            +
                end
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                it 'is equal to the expanded basename of app_file' do
         
     | 
| 
      
 329 
     | 
    
         
            +
                  @base.app_file = __FILE__
         
     | 
| 
      
 330 
     | 
    
         
            +
                  assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
         
     | 
| 
      
 331 
     | 
    
         
            +
             
     | 
| 
      
 332 
     | 
    
         
            +
                  @default.app_file = __FILE__
         
     | 
| 
      
 333 
     | 
    
         
            +
                  assert_equal File.expand_path(File.dirname(__FILE__)), @default.root
         
     | 
| 
      
 334 
     | 
    
         
            +
                end
         
     | 
| 
      
 335 
     | 
    
         
            +
              end
         
     | 
| 
      
 336 
     | 
    
         
            +
             
     | 
| 
      
 337 
     | 
    
         
            +
              describe 'views' do
         
     | 
| 
      
 338 
     | 
    
         
            +
                it 'is nil if root is not set' do
         
     | 
| 
      
 339 
     | 
    
         
            +
                  assert @base.views.nil?
         
     | 
| 
      
 340 
     | 
    
         
            +
                  assert @default.views.nil?
         
     | 
| 
      
 341 
     | 
    
         
            +
                end
         
     | 
| 
      
 342 
     | 
    
         
            +
             
     | 
| 
      
 343 
     | 
    
         
            +
                it 'is set to root joined with views/' do
         
     | 
| 
      
 344 
     | 
    
         
            +
                  @base.root = File.dirname(__FILE__)
         
     | 
| 
      
 345 
     | 
    
         
            +
                  assert_equal File.dirname(__FILE__) + "/views", @base.views
         
     | 
| 
      
 346 
     | 
    
         
            +
             
     | 
| 
      
 347 
     | 
    
         
            +
                  @default.root = File.dirname(__FILE__)
         
     | 
| 
      
 348 
     | 
    
         
            +
                  assert_equal File.dirname(__FILE__) + "/views", @default.views
         
     | 
| 
      
 349 
     | 
    
         
            +
                end
         
     | 
| 
      
 350 
     | 
    
         
            +
              end
         
     | 
| 
      
 351 
     | 
    
         
            +
             
     | 
| 
      
 352 
     | 
    
         
            +
              describe 'public' do
         
     | 
| 
      
 353 
     | 
    
         
            +
                it 'is nil if root is not set' do
         
     | 
| 
      
 354 
     | 
    
         
            +
                  assert @base.public.nil?
         
     | 
| 
      
 355 
     | 
    
         
            +
                  assert @default.public.nil?
         
     | 
| 
      
 356 
     | 
    
         
            +
                end
         
     | 
| 
      
 357 
     | 
    
         
            +
             
     | 
| 
      
 358 
     | 
    
         
            +
                it 'is set to root joined with public/' do
         
     | 
| 
      
 359 
     | 
    
         
            +
                  @base.root = File.dirname(__FILE__)
         
     | 
| 
      
 360 
     | 
    
         
            +
                  assert_equal File.dirname(__FILE__) + "/public", @base.public
         
     | 
| 
      
 361 
     | 
    
         
            +
             
     | 
| 
      
 362 
     | 
    
         
            +
                  @default.root = File.dirname(__FILE__)
         
     | 
| 
      
 363 
     | 
    
         
            +
                  assert_equal File.dirname(__FILE__) + "/public", @default.public
         
     | 
| 
      
 364 
     | 
    
         
            +
                end
         
     | 
| 
      
 365 
     | 
    
         
            +
              end
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
              describe 'lock' do
         
     | 
| 
      
 368 
     | 
    
         
            +
                it 'is disabled by default' do
         
     | 
| 
      
 369 
     | 
    
         
            +
                  assert ! @base.lock?
         
     | 
| 
      
 370 
     | 
    
         
            +
                end
         
     | 
| 
       102 
371 
     | 
    
         
             
              end
         
     | 
| 
       103 
372 
     | 
    
         
             
            end
         
     |