Skip to content
Newer
Older
100644 94 lines (73 sloc) 2.01 KB
f3ce689 @rtomayko set RACK_ENV in test/helper.rb to ensure sane environment
rtomayko authored Apr 25, 2009
1 ENV['RACK_ENV'] = 'test'
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored Sep 19, 2010
2 Encoding.default_external = "UTF-8" if defined? Encoding
f3ce689 @rtomayko set RACK_ENV in test/helper.rb to ensure sane environment
rtomayko authored Apr 25, 2009
3
d269bf5 @rkh add some test guards for rbx
rkh authored Feb 21, 2011
4 RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
5
9d32965 @rtomayko Don't require rubygems in tests; do fall back if necessary
rtomayko authored Jan 20, 2009
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 Mar 26, 2009
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 Jan 20, 2009
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 Mar 26, 2009
19 require 'contest'
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored Mar 28, 2009
20 require 'rack/test'
21 require 'sinatra/base'
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored Feb 14, 2009
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 Mar 13, 2011
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 Mar 26, 2009
34 Sinatra::Base.set :environment, :test
35
f9b13ee @sr Don't depend on sinatra/test/unit in internal test
sr authored Feb 14, 2009
36 class Test::Unit::TestCase
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored Mar 28, 2009
37 include Rack::Test::Methods
c00a25e @rtomayko Test framework refactoring
rtomayko authored Jan 13, 2009
38
ff0d068 @sr Use contest instead of test/spec/mini
sr authored Mar 26, 2009
39 class << self
40 alias_method :it, :test
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored Jan 23, 2009
41 end
42
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored Mar 28, 2009
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 Jan 13, 2009
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 Jan 15, 2009
55
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored Mar 28, 2009
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 Dec 23, 2010
64 def assert_body(value)
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored Dec 24, 2010
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 Dec 23, 2010
66 end
67
94bdb1c @rkh prepare for Tilt 1.3 (while remaining compatible with 1.2)
rkh authored Apr 13, 2011
68 def assert_include(str, substr)
69 assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
70 end
71
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored Mar 28, 2009
72 # Delegate other missing methods to response.
73 def method_missing(name, *args, &block)
74 if response && response.respond_to?(name)
75 response.send(name, *args, &block)
76 else
77 super
78 end
79 end
80
81 # Also check response since we delegate there.
82 def respond_to?(symbol, include_private=false)
83 super || (response && response.respond_to?(symbol, include_private))
84 end
85
86 # Do not output warnings for the duration of the block.
87 def silence_warnings
88 $VERBOSE, v = nil, $VERBOSE
89 yield
90 ensure
91 $VERBOSE = v
92 end
6569d1b @bdimcheff Added route block params in routing statements [#140]
bdimcheff authored Jan 28, 2009
93 end
Something went wrong with that request. Please try again.