1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/test/base_test.rb
Ryan Tomayko 49c60151bf Fix ruby warnings
Cleans up all warnings generated from Sinatra. There's still
a bunch of warnings coming from HAML, though. It would be nice
if we could use Kernel#warn for deprecation notices but that's
going to be annoying if there's a bunch of unrelated warnings
from other libs.
2009-01-09 01:49:50 -08:00

72 lines
1.6 KiB
Ruby

require 'test/spec'
require 'sinatra/base'
require 'sinatra/test'
describe 'Sinatra::Base' do
include Sinatra::Test
it 'includes Rack::Utils' do
Sinatra::Base.should.include Rack::Utils
end
it 'can be used as a Rack application' do
mock_app {
get '/' do
'Hello World'
end
}
@app.should.respond_to :call
request = Rack::MockRequest.new(@app)
response = request.get('/')
response.should.be.ok
response.body.should.equal 'Hello World'
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)
middleware.app.should.be app
request = Rack::MockRequest.new(middleware)
response = request.get('/')
response.should.be.ok
response.body.should.equal 'Hello World'
response = request.get('/goodbye')
response.should.be.ok
response.body.should.equal 'Goodbye World'
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')
response.should.be.ok
response.body.should.equal 'foo'
request = Rack::MockRequest.new(app)
response = request.get('/foo')
response.should.be.ok
response.body.should.equal 'not foo'
end
end