Method: Cramp::TestCase#request_body

Defined in:
lib/cramp/test_case.rb

#request_body(method, path, options = {}, headers = {}, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cramp/test_case.rb', line 34

def request_body(method, path, options = {}, headers = {}, &block)
  callback = options.delete(:callback) || block
  response_callback = proc do |response|
    # 'halt' returns a String, not an async Body object
    if response.last.is_a? String
      callback.call(response.last)
    else
      response.last.each {|chunk| callback.call(chunk) }
    end
  end
  headers = headers.merge('async.callback' => response_callback)

  EM.run do
    catch(:async) { @request.request(method, path, headers) }
  end
end