Class: WebMock::RequestExecutionVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/request_execution_verifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_pattern = nil, expected_times_executed = nil, at_least_times_executed = nil, at_most_times_executed = nil) ⇒ RequestExecutionVerifier

Returns a new instance of RequestExecutionVerifier.


6
7
8
9
10
11
# File 'lib/webmock/request_execution_verifier.rb', line 6

def initialize(request_pattern = nil, expected_times_executed = nil, at_least_times_executed = nil, at_most_times_executed = nil)
  @request_pattern = request_pattern
  @expected_times_executed = expected_times_executed
  @at_least_times_executed = at_least_times_executed
  @at_most_times_executed = at_most_times_executed
end

Instance Attribute Details

#at_least_times_executedObject

Returns the value of attribute at_least_times_executed


4
5
6
# File 'lib/webmock/request_execution_verifier.rb', line 4

def at_least_times_executed
  @at_least_times_executed
end

#at_most_times_executedObject

Returns the value of attribute at_most_times_executed


4
5
6
# File 'lib/webmock/request_execution_verifier.rb', line 4

def at_most_times_executed
  @at_most_times_executed
end

#expected_times_executedObject

Returns the value of attribute expected_times_executed


4
5
6
# File 'lib/webmock/request_execution_verifier.rb', line 4

def expected_times_executed
  @expected_times_executed
end

#request_patternObject

Returns the value of attribute request_pattern


4
5
6
# File 'lib/webmock/request_execution_verifier.rb', line 4

def request_pattern
  @request_pattern
end

#times_executedObject

Returns the value of attribute times_executed


4
5
6
# File 'lib/webmock/request_execution_verifier.rb', line 4

def times_executed
  @times_executed
end

Class Method Details

.executed_requests_messageObject


48
49
50
# File 'lib/webmock/request_execution_verifier.rb', line 48

def self.executed_requests_message
  "\n\nThe following requests were made:\n\n#{RequestRegistry.instance}\n" + "="*60
end

Instance Method Details

#descriptionObject


36
37
38
# File 'lib/webmock/request_execution_verifier.rb', line 36

def description
  "request #{request_pattern} #{quantity_phrase.strip}"
end

#does_not_match?Boolean

Returns:

  • (Boolean)

26
27
28
29
30
31
32
33
34
# File 'lib/webmock/request_execution_verifier.rb', line 26

def does_not_match?
  @times_executed =
  RequestRegistry.instance.times_executed(@request_pattern)
  if @expected_times_executed
    @times_executed != @expected_times_executed
  else
    @times_executed == 0
  end
end

#failure_messageObject


40
41
42
# File 'lib/webmock/request_execution_verifier.rb', line 40

def failure_message
  failure_message_phrase(false)
end

#failure_message_when_negatedObject


44
45
46
# File 'lib/webmock/request_execution_verifier.rb', line 44

def failure_message_when_negated
  failure_message_phrase(true)
end

#matches?Boolean

Returns:

  • (Boolean)

13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/webmock/request_execution_verifier.rb', line 13

def matches?
  @times_executed =
    RequestRegistry.instance.times_executed(@request_pattern)

  if @at_least_times_executed
    @times_executed >= @at_least_times_executed
  elsif @at_most_times_executed
    @times_executed <= @at_most_times_executed
  else
    @times_executed == (@expected_times_executed || 1)
  end
end