Module: VCR::LibraryHooks::WebMock::Helpers

Included in:
VCR::LibraryHooks::WebMock, RequestHandler
Defined in:
lib/vcr/library_hooks/webmock.rb

Instance Method Summary collapse

Instance Method Details

#request_headers_for(webmock_request) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/vcr/library_hooks/webmock.rb', line 55

def request_headers_for(webmock_request)
  return nil unless webmock_request.headers

  # WebMock hooks deeply into a Excon at a place where it manually adds a "Host"
  # header, but this isn't a header we actually care to store...
  webmock_request.headers.dup.tap do |headers|
    headers.delete("Host")
  end
end

#typed_request_for(webmock_request, remove = false) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vcr/library_hooks/webmock.rb', line 71

def typed_request_for(webmock_request, remove = false)
  if webmock_request.instance_variables.find { |v| v.to_sym == :@__typed_vcr_request }
    meth = remove ? :remove_instance_variable : :instance_variable_get
    return webmock_request.send(meth, :@__typed_vcr_request)
  end

  warn <<-EOS.gsub(/^\s+\|/, '')
    |WARNING: There appears to be a bug in WebMock's after_request hook
    |         and VCR is attempting to work around it. Some VCR features
    |         may not work properly.
  EOS

  Request::Typed.new(vcr_request_for(webmock_request), :unknown)
end

#vcr_request_for(webmock_request) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/vcr/library_hooks/webmock.rb', line 36

def vcr_request_for(webmock_request)
  VCR::Request.new \
    webmock_request.method,
    webmock_request.uri.to_s,
    webmock_request.body,
    request_headers_for(webmock_request)
end

#vcr_response_for(webmock_response) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/vcr/library_hooks/webmock.rb', line 45

def vcr_response_for(webmock_response)
  VCR::Response.new \
    VCR::ResponseStatus.new(*webmock_response.status),
    webmock_response.headers,
    webmock_response.body,
    nil
end