Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (79 sloc) 2.236 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
a9d89d2 @rkh add markdown, rdoc and textile nesting tests
rkh authored
68 def assert_like(a,b)
69 pattern = /\s*\n\s*| id=['"][^"']*["']/
70 assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "")
71 end
72
a735e34 @rkh prepare for Tilt 1.3 (while remaining compatible with 1.2)
rkh authored
73 def assert_include(str, substr)
74 assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
75 end
76
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
77 # Delegate other missing methods to response.
78 def method_missing(name, *args, &block)
79 if response && response.respond_to?(name)
80 response.send(name, *args, &block)
81 else
82 super
83 end
a9d89d2 @rkh add markdown, rdoc and textile nesting tests
rkh authored
84 rescue Rack::Test::Error
85 super
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
86 end
87
88 # Also check response since we delegate there.
89 def respond_to?(symbol, include_private=false)
90 super || (response && response.respond_to?(symbol, include_private))
91 end
92
93 # Do not output warnings for the duration of the block.
94 def silence_warnings
95 $VERBOSE, v = nil, $VERBOSE
96 yield
97 ensure
98 $VERBOSE = v
99 end
6569d1b @bdimcheff Added route block params in routing statements [#140]
bdimcheff authored
100 end
Something went wrong with that request. Please try again.