Skip to content
Newer
Older
100644 77 lines (60 sloc) 1.56 KB
f3ce689 @rtomayko set RACK_ENV in test/helper.rb to ensure sane environment
rtomayko authored
1 ENV['RACK_ENV'] = 'test'
2
9d32965 @rtomayko Don't require rubygems in tests; do fall back if necessary
rtomayko authored
3 begin
4 require 'rack'
5 rescue LoadError
6 require 'rubygems'
7 require 'rack'
8 end
9
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
10 testdir = File.dirname(__FILE__)
11 $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
12
9d32965 @rtomayko Don't require rubygems in tests; do fall back if necessary
rtomayko authored
13 libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
14 $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
15
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
16 require 'contest'
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
17 require 'rack/test'
18 require 'sinatra/base'
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored
19
20 class Sinatra::Base
21 # Allow assertions in request context
22 include Test::Unit::Assertions
23 end
24
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
25 Sinatra::Base.set :environment, :test
26
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored
27 class Test::Unit::TestCase
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
28 include Rack::Test::Methods
c00a25e @rtomayko Test framework refactoring
rtomayko authored
29
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
30 class << self
31 alias_method :it, :test
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
32 end
33
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
34 alias_method :response, :last_response
35
36 setup do
37 Sinatra::Base.set :environment, :test
38 end
39
c00a25e @rtomayko Test framework refactoring
rtomayko authored
40 # Sets up a Sinatra::Base subclass defined with the block
41 # given. Used in setup or individual spec methods to establish
42 # the application.
43 def mock_app(base=Sinatra::Base, &block)
44 @app = Sinatra.new(base, &block)
45 end
661090e @rtomayko Allow assertions in mock_app request context
rtomayko authored
46
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
47 def app
48 Rack::Lint.new(@app)
49 end
50
51 def body
52 response.body.to_s
53 end
54
55 # Delegate other missing methods to response.
56 def method_missing(name, *args, &block)
57 if response && response.respond_to?(name)
58 response.send(name, *args, &block)
59 else
60 super
61 end
62 end
63
64 # Also check response since we delegate there.
65 def respond_to?(symbol, include_private=false)
66 super || (response && response.respond_to?(symbol, include_private))
67 end
68
69 # Do not output warnings for the duration of the block.
70 def silence_warnings
71 $VERBOSE, v = nil, $VERBOSE
72 yield
73 ensure
74 $VERBOSE = v
75 end
6569d1b @bdimcheff Added route block params in routing statements [#140]
bdimcheff authored
76 end
Something went wrong with that request. Please try again.