# 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
# File lib/webmock/stub_registry.rb, line 33 def register_request_stub(stub) request_stubs.insert(0, stub) stub end
# File lib/webmock/stub_registry.rb, line 38 def registered_request?(request_signature) request_stub_for(request_signature) end
Generated with the Darkfish Rdoc Generator 2.