Class: VCR::HttpStubbingAdapters::WebMock
- Inherits:
-
Base
- Object
- Base
- VCR::HttpStubbingAdapters::WebMock
show all
- Defined in:
- lib/vcr/http_stubbing_adapters/webmock.rb
Constant Summary
collapse
- VERSION_REQUIREMENT =
'1.1.0'
Class Method Summary
collapse
Methods inherited from Base
meets_version_requirement?, with_http_connections_allowed_set_to
Class Method Details
.check_version! ⇒ Object
10
11
12
13
14
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 10
def check_version!
unless meets_version_requirement?(::WebMock.version, VERSION_REQUIREMENT)
raise "You are using WebMock #{::WebMock.version}. VCR requires version #{VERSION_REQUIREMENT} or greater."
end
end
|
.create_stubs_checkpoint(checkpoint_name) ⇒ Object
38
39
40
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 38
def create_stubs_checkpoint(checkpoint_name)
checkpoints[checkpoint_name] = ::WebMock::RequestRegistry.instance.request_stubs.dup
end
|
.http_connections_allowed=(value) ⇒ Object
20
21
22
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 20
def http_connections_allowed=(value)
::WebMock::Config.instance.allow_net_connect = value
end
|
.http_connections_allowed? ⇒ Boolean
16
17
18
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 16
def http_connections_allowed?
::WebMock::Config.instance.allow_net_connect
end
|
.request_stubbed?(method, uri) ⇒ Boolean
46
47
48
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 46
def request_stubbed?(method, uri)
!!::WebMock.registered_request?(::WebMock::RequestSignature.new(method, uri))
end
|
.request_uri(net_http, request) ⇒ Object
50
51
52
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 50
def request_uri(net_http, request)
::WebMock::NetHTTPUtility.request_signature_from_request(net_http, request).uri.to_s
end
|
.restore_stubs_checkpoint(checkpoint_name) ⇒ Object
42
43
44
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 42
def restore_stubs_checkpoint(checkpoint_name)
::WebMock::RequestRegistry.instance.request_stubs = checkpoints.delete(checkpoint_name)
end
|
.stub_requests(recorded_responses) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/vcr/http_stubbing_adapters/webmock.rb', line 24
def stub_requests(recorded_responses)
requests = Hash.new([])
recorded_responses.each do |rr|
requests[[rr.method, rr.uri]] += [rr.response]
end
requests.each do |request, responses|
::WebMock.stub_request(request.first, request.last).
to_return(responses.map{ |r| response_hash(r) })
end
end
|