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-02-14 14:15:50 -05:00
|
|
|
require 'sinatra/test'
|
|
|
|
|
|
|
|
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
|
|
|
|
include Sinatra::Test
|
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-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-02-14 14:22:52 -05:00
|
|
|
|
|
|
|
def restore_default_options
|
|
|
|
Sinatra::Default.set(
|
2009-02-22 08:41:49 -05:00
|
|
|
:environment => :development,
|
2009-02-14 14:22:52 -05:00
|
|
|
:raise_errors => Proc.new { test? },
|
2009-01-23 05:37:43 -05:00
|
|
|
:show_exceptions => Proc.new { development? },
|
2009-02-14 14:22:52 -05:00
|
|
|
:dump_errors => true,
|
|
|
|
:sessions => false,
|
2009-02-22 08:41:49 -05:00
|
|
|
:logging => Proc.new { ! test? },
|
2009-02-14 14:22:52 -05:00
|
|
|
:methodoverride => true,
|
|
|
|
:static => true,
|
2009-02-22 08:41:49 -05:00
|
|
|
:run => Proc.new { ! test? }
|
2009-02-14 14:22:52 -05:00
|
|
|
)
|
|
|
|
end
|
2009-01-13 12:53:53 -05:00
|
|
|
end
|
2009-01-15 07:04:10 -05:00
|
|
|
|
2009-01-28 15:27:32 -05:00
|
|
|
# Do not output warnings for the duration of the block.
|
|
|
|
def silence_warnings
|
|
|
|
$VERBOSE, v = nil, $VERBOSE
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$VERBOSE = v
|
|
|
|
end
|