Class: Sinatra::Async::Test::AsyncSession

Inherits:
Rack::MockSession
  • Object
show all
Defined in:
lib/sinatra/async/test.rb

Defined Under Namespace

Classes: AsyncCloser

Instance Method Summary collapse

Instance Method Details

#handle_last_response(uri, env, status, headers, body) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/sinatra/async/test.rb', line 40

def handle_last_response(uri, env, status, headers, body)
  @last_response = Rack::MockResponse.new(status, headers, body, env["rack.errors"].flush)
  body.close if body.respond_to?(:close)

  cookie_jar.merge(last_response.headers["Set-Cookie"], uri)

  @after_request.each { |hook| hook.call }
  @last_response
end

#request(uri, env) ⇒ Object



33
34
35
36
37
38
# File 'lib/sinatra/async/test.rb', line 33

def request(uri, env)
  env['async.callback'] = lambda { |r| s,h,b = *r; handle_last_response(uri, env, s,h,b) }
  env['async.close'] = AsyncCloser.new
  catch(:async) { super }
  @last_response ||= Rack::MockResponse.new(-1, {}, [], env["rack.errors"].flush)
end

#reset_last_responseObject



50
51
52
# File 'lib/sinatra/async/test.rb', line 50

def reset_last_response
  @last_response = nil
end