Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (70 sloc) 1.926 kB
f3ce689 @rtomayko set RACK_ENV in test/helper.rb to ensure sane environment
rtomayko authored
1 ENV['RACK_ENV'] = 'test'
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored
2 Encoding.default_external = "UTF-8" if defined? Encoding
f3ce689 @rtomayko set RACK_ENV in test/helper.rb to ensure sane environment
rtomayko authored
3
d269bf5 @rkh add some test guards for rbx
rkh authored
4 RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
5
9d32965 @rtomayko Don't require rubygems in tests; do fall back if necessary
rtomayko authored
6 begin
7 require 'rack'
8 rescue LoadError
9 require 'rubygems'
10 require 'rack'
11 end
12
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
13 testdir = File.dirname(__FILE__)
14 $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
15
9d32965 @rtomayko Don't require rubygems in tests; do fall back if necessary
rtomayko authored
16 libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
17 $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
18
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
19 require 'contest'
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
20 require 'rack/test'
21 require 'sinatra/base'
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored
22
23 class Sinatra::Base
24 # Allow assertions in request context
25 include Test::Unit::Assertions
26 end
27
654eebb @rkh more tests for sessions
rkh authored
28 class Rack::Builder
29 def include?(middleware)
30 @ins.any? { |m| p m ; middleware === m }
31 end
32 end
33
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
34 Sinatra::Base.set :environment, :test
35
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored
36 class Test::Unit::TestCase
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
37 include Rack::Test::Methods
c00a25e @rtomayko Test framework refactoring
rtomayko authored
38
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
39 class << self
40 alias_method :it, :test
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
41 end
42
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
43 alias_method :response, :last_response
44
45 setup do
46 Sinatra::Base.set :environment, :test
47 end
48
c00a25e @rtomayko Test framework refactoring
rtomayko authored
49 # Sets up a Sinatra::Base subclass defined with the block
50 # given. Used in setup or individual spec methods to establish
51 # the application.
52 def mock_app(base=Sinatra::Base, &block)
53 @app = Sinatra.new(base, &block)
54 end
661090e @rtomayko Allow assertions in mock_app request context
rtomayko authored
55
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
56 def app
57 Rack::Lint.new(@app)
58 end
59
60 def body
61 response.body.to_s
62 end
63
9192432 @rkh fix tests for rdoc 3.0
rkh authored
64 def assert_body(value)
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
65 assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
9192432 @rkh fix tests for rdoc 3.0
rkh authored
66 end
67
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
68 # Delegate other missing methods to response.
69 def method_missing(name, *args, &block)
70 if response && response.respond_to?(name)
71 response.send(name, *args, &block)
72 else
73 super
74 end
75 end
76
77 # Also check response since we delegate there.
78 def respond_to?(symbol, include_private=false)
79 super || (response && response.respond_to?(symbol, include_private))
80 end
81
82 # Do not output warnings for the duration of the block.
83 def silence_warnings
84 $VERBOSE, v = nil, $VERBOSE
85 yield
86 ensure
87 $VERBOSE = v
88 end
6569d1b @bdimcheff Added route block params in routing statements [#140]
bdimcheff authored
89 end
Something went wrong with that request. Please try again.