Parent

Included Modules

Class/Module Index [+]

Quicksearch

WebMock::StubRegistry

Attributes

global_stub[RW]
request_stubs[RW]

Public Class Methods

new() click to toggle source
# File lib/webmock/stub_registry.rb, line 9
def initialize
  reset!
end

Public Instance Methods

global_stub_block=(block) click to toggle source
# File lib/webmock/stub_registry.rb, line 17
def global_stub_block=(block)
  self.global_stub = ::WebMock::RequestStub.new(:any, /.*/)

  # This hash contains the responses returned by the block,
  # keyed by the exact request (using the object_id).
  # That way, there's no race condition in case #to_return
  # doesn't run immediately after stub.with.
  responses = {}

  self.global_stub.with { |request|
    responses[request.object_id] = block.call(request)
  }.to_return(lambda { |request| responses.delete(request.object_id) })

  register_request_stub(self.global_stub)
end
register_request_stub(stub) click to toggle source
# File lib/webmock/stub_registry.rb, line 33
def register_request_stub(stub)
  request_stubs.insert(0, stub)
  stub
end
registered_request?(request_signature) click to toggle source
# File lib/webmock/stub_registry.rb, line 38
def registered_request?(request_signature)
  request_stub_for(request_signature)
end
reset!() click to toggle source
# File lib/webmock/stub_registry.rb, line 13
def reset!
  self.request_stubs = global_stub ? [global_stub] : []
end
response_for_request(request_signature) click to toggle source
# File lib/webmock/stub_registry.rb, line 42
def response_for_request(request_signature)
  stub = request_stub_for(request_signature)
  stub ? evaluate_response_for_request(stub.response, request_signature) : nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.