Method: FakeWeb::Responder#response

Defined in:
lib/fake_web/responder.rb

#response {|response| ... } ⇒ Object

Yields:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fake_web/responder.rb', line 19

def response(&block)
  if has_baked_response?
    response = baked_response
  else
    code, msg = meta_information
    response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
    response.instance_variable_set(:@body, body)
    headers_extracted_from_options.each do |name, value|
      if value.respond_to?(:each)
        value.each { |v| response.add_field(name, v) }
      else
        response[name] = value
      end
    end
  end

  response.instance_variable_set(:@read, true)
  response.extend FakeWeb::Response

  optionally_raise(response)

  yield response if block_given?

  response
end