Module: FakeWebMatcher::Extension

Defined in:
lib/fake_web_matcher/extension.rb

Overview

Extension for FakeWeb::Registry, to track requests made for given URIs. The code that includes this into FakeWeb is in the base FakeWebMatcher module.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fake_web_matcher/extension.rb', line 8

def self.included(base)
  base.class_eval do
    # Keep the original response_for method
    alias_method :response_without_request_tracking, :response_for
    
    # Overwrites the existing FakeWeb::Registry#response method, to ensure
    # requests are tracked. Returns the usual stubbed response.
    # 
    # @param [Symbol] method HTTP method
    # @param [String] uri URI requested
    # @param [Proc] block The block passed into Net::HTTP requests
    # @return [String] The stubbed page response
    # 
    def response_for(method, uri, &block)
      requests << [method, uri]
      response_without_request_tracking(method, uri, &block)
    end
  end
end

Instance Method Details

#clear_requestsObject

Clears the stored request list



39
40
41
# File 'lib/fake_web_matcher/extension.rb', line 39

def clear_requests
  requests.clear
end

#requestsArray

A list of the requests, kept as an array of arrays, where each child array has two values - the method and the URI.

Returns:

  • (Array)

    Recorded requests



33
34
35
# File 'lib/fake_web_matcher/extension.rb', line 33

def requests
  @requests ||= []
end