Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (91 sloc) 2.725 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 of j...
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
2670387 @rkh start working on README tests
rkh authored
41 alias_method :section, :context
42 end
43
44 def self.example(desc = nil, &block)
45 @example_count = 0 unless instance_variable_defined? :@example_count
46 @example_count += 1
47 it(desc || "Example #{@example_count}", &block)
60bdca9 @sr Initial Sinatra-specific ShowException middleware
sr authored
48 end
49
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
50 alias_method :response, :last_response
51
52 setup do
53 Sinatra::Base.set :environment, :test
54 end
55
c00a25e @rtomayko Test framework refactoring
rtomayko authored
56 # Sets up a Sinatra::Base subclass defined with the block
57 # given. Used in setup or individual spec methods to establish
58 # the application.
59 def mock_app(base=Sinatra::Base, &block)
60 @app = Sinatra.new(base, &block)
61 end
661090e @rtomayko Allow assertions in mock_app request context
rtomayko authored
62
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
63 def app
64 Rack::Lint.new(@app)
65 end
66
67 def body
68 response.body.to_s
69 end
70
9192432 @rkh fix tests for rdoc 3.0
rkh authored
71 def assert_body(value)
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
72 assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
9192432 @rkh fix tests for rdoc 3.0
rkh authored
73 end
74
a9d89d2 @rkh add markdown, rdoc and textile nesting tests
rkh authored
75 def assert_like(a,b)
5044802 @rkh fix rdoc test, closes #270
rkh authored
76 pattern = /id=['"][^"']*["']|\s+/
a9d89d2 @rkh add markdown, rdoc and textile nesting tests
rkh authored
77 assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "")
78 end
79
a735e34 @rkh prepare for Tilt 1.3 (while remaining compatible with 1.2)
rkh authored
80 def assert_include(str, substr)
81 assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
82 end
83
2670387 @rkh start working on README tests
rkh authored
84 def options(uri, params = {}, env = {}, &block)
85 request(uri, env.merge(:method => "OPTIONS", :params => params), &block)
86 end
87
88 def patch(uri, params = {}, env = {}, &block)
89 request(uri, env.merge(:method => "PATCH", :params => params), &block)
90 end
91
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
92 # Delegate other missing methods to response.
93 def method_missing(name, *args, &block)
94 if response && response.respond_to?(name)
95 response.send(name, *args, &block)
96 else
97 super
98 end
a9d89d2 @rkh add markdown, rdoc and textile nesting tests
rkh authored
99 rescue Rack::Test::Error
100 super
2fa9fd8 @sr Use Rack::Test instead of Sinatra::Test for tests
sr authored
101 end
102
103 # Also check response since we delegate there.
104 def respond_to?(symbol, include_private=false)
105 super || (response && response.respond_to?(symbol, include_private))
106 end
107
108 # Do not output warnings for the duration of the block.
109 def silence_warnings
110 $VERBOSE, v = nil, $VERBOSE
111 yield
112 ensure
113 $VERBOSE = v
114 end
6569d1b @bdimcheff Added route block params in routing statements [#140]
bdimcheff authored
115 end
Something went wrong with that request. Please try again.