Sha256: 8b8ebf7e0b660601585d4a9ed5730476022d69d3684a5871052a3acec63663e4

Contents?: true

Size: 1.57 KB

Versions: 26

Compression:

Stored size: 1.57 KB

Contents

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

describe 'Sinatra::Base' do
  it 'includes Rack::Utils' do
    assert Sinatra::Base.included_modules.include?(Rack::Utils)
  end

  it 'can be used as a Rack application' do
    mock_app {
      get '/' do
        'Hello World'
      end
    }
    assert @app.respond_to?(:call)

    request = Rack::MockRequest.new(@app)
    response = request.get('/')
    assert response.ok?
    assert_equal 'Hello World', response.body
  end

  it 'can be used as Rack middleware' do
    app = lambda { |env| [200, {}, ['Goodbye World']] }
    mock_middleware =
      mock_app {
        get '/' do
          'Hello World'
        end
        get '/goodbye' do
          @app.call(request.env)
        end
      }
    middleware = mock_middleware.new(app)
    assert_same app, middleware.app

    request = Rack::MockRequest.new(middleware)
    response = request.get('/')
    assert response.ok?
    assert_equal 'Hello World', response.body

    response = request.get('/goodbye')
    assert response.ok?
    assert_equal 'Goodbye World', response.body
  end

  it 'can take multiple definitions of a route' do
    app = mock_app {
      user_agent(/Foo/)
      get '/foo' do
        'foo'
      end

      get '/foo' do
        'not foo'
      end
    }

    request = Rack::MockRequest.new(app)
    response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
    assert response.ok?
    assert_equal 'foo', response.body

    request = Rack::MockRequest.new(app)
    response = request.get('/foo')
    assert response.ok?
    assert_equal 'not foo', response.body
  end
end

Version data entries

26 entries across 26 versions & 8 rubygems

Version Path
Syd-sinatra-0.9.0.2 test/base_test.rb
Syd-sinatra-0.9.0.4 test/base_test.rb
bmizerany-sinatra-0.8.10 test/base_test.rb
bmizerany-sinatra-0.8.9 test/base_test.rb
bmizerany-sinatra-0.9.0.2 test/base_test.rb
bmizerany-sinatra-0.9.0.4 test/base_test.rb
p8-castronaut-0.6.1.1 vendor/sinatra/test/base_test.rb
relevance-castronaut-0.6.0 vendor/sinatra/test/base_test.rb
relevance-castronaut-0.6.1 vendor/sinatra/test/base_test.rb
relevance-castronaut-0.7.4 vendor/sinatra/test/base_test.rb
relevance-castronaut-0.7.5 vendor/sinatra/test/base_test.rb
rtomayko-sinatra-0.8.10 test/base_test.rb
rtomayko-sinatra-0.9.0.2 test/base_test.rb
sinatra-sinatra-0.8.10 test/base_test.rb
sinatra-sinatra-0.8.9 test/base_test.rb
sinatra-sinatra-0.9.0.1 test/base_test.rb
sinatra-sinatra-0.9.0.2 test/base_test.rb
sinatra-sinatra-0.9.0.4 test/base_test.rb
sinatra-sinatra-0.9.0 test/base_test.rb
nbudin-castronaut-0.7.5 vendor/sinatra/test/base_test.rb