Class: WebMock::RequestRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/webmock/request_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequestRegistry

Returns a new instance of RequestRegistry.



8
9
10
# File 'lib/webmock/request_registry.rb', line 8

def initialize
  reset!
end

Instance Attribute Details

#requested_signaturesObject

Returns the value of attribute requested_signatures.



6
7
8
# File 'lib/webmock/request_registry.rb', line 6

def requested_signatures
  @requested_signatures
end

Instance Method Details

#reset!Object



12
13
14
# File 'lib/webmock/request_registry.rb', line 12

def reset!
  self.requested_signatures = Util::HashCounter.new
end

#times_executed(request_pattern) ⇒ Object



16
17
18
19
20
# File 'lib/webmock/request_registry.rb', line 16

def times_executed(request_pattern)
  self.requested_signatures.select do |request_signature|
    request_pattern.matches?(request_signature)
  end.inject(0) { |sum, (_, times_executed)| sum + times_executed }
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webmock/request_registry.rb', line 22

def to_s
  if requested_signatures.hash.empty?
    "No requests were made."
  else
    text = "".dup
    self.requested_signatures.each do |request_signature, times_executed|
      text << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n"
    end
    text
  end
end