Class: FakeWebMatcher::RequestMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_web_matcher/request_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RequestMatcher

Create a new matcher.

Parameters:

  • method (Symbol) —

    The HTTP method. Defaults to :any if not supplied.

  • uri (String, Regexp) —

    The URI to check for



36
37
38
# File 'lib/fake_web_matcher/request_matcher.rb', line 36

def initialize(*args)
  @method, @url = args_split(*args)
end

Instance Attribute Details

#method ⇒ Object (readonly)

Returns the value of attribute method.



29
30
31
# File 'lib/fake_web_matcher/request_matcher.rb', line 29

def method
  @method
end

#url ⇒ Object (readonly)

Returns the value of attribute url.



29
30
31
# File 'lib/fake_web_matcher/request_matcher.rb', line 29

def url
  @url
end

Instance Method Details

#failure_message ⇒ String

Failure message if the URI should have been requested.

Returns:

  • (String) —

    failure message



57
58
59
# File 'lib/fake_web_matcher/request_matcher.rb', line 57

def failure_message
  regex?(@url) ? regex_failure_message : url_failure_message
end

#failure_message_when_negated ⇒ String

Failure message if the URI should not have been requested.

Returns:

  • (String) —

    failure message



73
74
75
# File 'lib/fake_web_matcher/request_matcher.rb', line 73

def failure_message_when_negated
  regex?(@url) ? regex_negative_failure_message : url_negative_failure_message
end

#matches?(fakeweb) ⇒ Boolean

Indication of whether there's a match on the URI from given requests.

Parameters:

  • FakeWeb (Module) —

    Module, necessary for RSpec, although not required internally.

Returns:

  • (Boolean) —

    true if the URI was requested, otherwise false.



46
47
48
49
50
51
# File 'lib/fake_web_matcher/request_matcher.rb', line 46

def matches?(fakeweb)
  !FakeWeb::Registry.instance.requests.detect { |req|
    method, url = args_split(*req)
    match_method(method) && match_url(url)
  }.nil?
end

#negative_failure_message ⇒ String

Failure message if the URI should not have been requested. (Deprecated)

Returns:

  • (String) —

    failure message



65
66
67
# File 'lib/fake_web_matcher/request_matcher.rb', line 65

def negative_failure_message
  regex?(@url) ? regex_negative_failure_message : url_negative_failure_message
end