test: add test harness with http and router tests

This commit is contained in:
dualfroz committed 2026-08-27 11:40:00 +02:00
1 parent b8e3b2cd55
commit c079abed00
6 files changed
+239

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
require 'prism'
require 'stringio'
module TestSupport
def env_for(method, path, headers: {}, body: nil, cookies: nil)
path_part, query = path.split('?', 2)
env = {
'REQUEST_METHOD' => method.to_s.upcase,
'PATH_INFO' => path_part,
'QUERY_STRING' => query.to_s,
'rack.input' => StringIO.new(body || ''),
'CONTENT_LENGTH' => (body ? body.bytesize.to_s : '0')
}
headers.each do |name, value|
if name.downcase == 'content-type'
env['CONTENT_TYPE'] = value
else
env["HTTP_#{name.upcase.tr('-', '_')}"] = value
end
end
env['HTTP_COOKIE'] = cookies if cookies
env
end
end