2009-04-25 12:17:11 -04:00
|
|
|
ENV['RACK_ENV'] = 'test'
|
|
|
|
|
2009-01-20 15:24:36 -05:00
|
|
|
begin
|
|
|
|
require 'rack'
|
|
|
|
rescue LoadError
|
|
|
|
require 'rubygems'
|
|
|
|
require 'rack'
|
|
|
|
end
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
testdir = File.dirname(__FILE__)
|
|
|
|
$LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
|
|
|
|
|
2009-01-20 15:24:36 -05:00
|
|
|
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
|
|
|
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
require 'contest'
|
2009-03-28 11:28:18 -04:00
|
|
|
require 'rack/test'
|
|
|
|
require 'sinatra/base'
|
2009-02-14 14:15:50 -05:00
|
|
|
|
|
|
|
class Sinatra::Base
|
|
|
|
# Allow assertions in request context
|
|
|
|
include Test::Unit::Assertions
|
|
|
|
end
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
Sinatra::Base.set :environment, :test
|
|
|
|
|
2009-02-14 14:15:50 -05:00
|
|
|
class Test::Unit::TestCase
|
2009-03-28 11:28:18 -04:00
|
|
|
include Rack::Test::Methods
|
2009-01-13 12:53:53 -05:00
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
class << self
|
|
|
|
alias_method :it, :test
|
2009-01-23 05:37:43 -05:00
|
|
|
end
|
|
|
|
|
2009-03-28 11:28:18 -04:00
|
|
|
alias_method :response, :last_response
|
|
|
|
|
|
|
|
setup do
|
|
|
|
Sinatra::Base.set :environment, :test
|
|
|
|
end
|
|
|
|
|
2009-01-13 12:53:53 -05:00
|
|
|
# Sets up a Sinatra::Base subclass defined with the block
|
|
|
|
# given. Used in setup or individual spec methods to establish
|
|
|
|
# the application.
|
|
|
|
def mock_app(base=Sinatra::Base, &block)
|
|
|
|
@app = Sinatra.new(base, &block)
|
|
|
|
end
|
2009-01-15 07:04:10 -05:00
|
|
|
|
2009-03-28 11:28:18 -04:00
|
|
|
def app
|
|
|
|
Rack::Lint.new(@app)
|
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
response.body.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
# Delegate other missing methods to response.
|
|
|
|
def method_missing(name, *args, &block)
|
|
|
|
if response && response.respond_to?(name)
|
|
|
|
response.send(name, *args, &block)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Also check response since we delegate there.
|
|
|
|
def respond_to?(symbol, include_private=false)
|
|
|
|
super || (response && response.respond_to?(symbol, include_private))
|
|
|
|
end
|
|
|
|
|
|
|
|
# Do not output warnings for the duration of the block.
|
|
|
|
def silence_warnings
|
|
|
|
$VERBOSE, v = nil, $VERBOSE
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$VERBOSE = v
|
|
|
|
end
|
2009-01-28 15:27:32 -05:00
|
|
|
end
|