blob: 2c9fa9a544f6b88088e4025fe7b8582f837fd799 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
require_relative 'assert_responses'
class RackTest < ActiveSupport::TestCase
include Rack::Test::Methods
include Warden::Test::Helpers
include AssertResponses
CONFIG_RU = (Rails.root + 'config.ru').to_s
OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first
def app
OUTER_APP
end
# inspired by rails 4
# -> actionpack/lib/action_dispatch/testing/assertions/response.rb
def assert_response(type, message = nil)
# RackTest does not know @response
response_code = last_response.status
message ||= "Expected response to be a <#{type}>, but was <#{response_code}>"
if Symbol === type
if [:success, :missing, :redirect, :error].include?(type)
assert last_response.send("#{type}?"), message
else
code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
assert_equal code, response_code, message
end
else
assert_equal type, response_code, message
end
end
end
|