Class: FakeWebMatcher::RequestMatcher
- Inherits:
-
Object
- Object
- FakeWebMatcher::RequestMatcher
- Defined in:
- lib/fake_web_matcher/request_matcher.rb
Overview
Matcher class, following RSpec’s expectations. Used to confirm whether a request has been made on a given method and URI.
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#failure_message ⇒ String
Failure message if the URI should have been requested.
-
#initialize(*args) ⇒ RequestMatcher
constructor
Create a new matcher.
-
#matches?(fakeweb) ⇒ Boolean
Indication of whether there’s a match on the URI from given requests.
-
#negative_failure_message ⇒ String
Failure message if the URI should not have been requested.
Constructor Details
#initialize(*args) ⇒ RequestMatcher
Create a new matcher.
13 14 15 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 13 def initialize(*args) @method, @url = args_split(*args) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 6 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 6 def url @url end |
Instance Method Details
#failure_message ⇒ String
Failure message if the URI should have been requested.
34 35 36 37 38 39 40 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 34 def if @method == :any "The URL #{@url} was not requested." else "The URL #{@url} was not requested using #{formatted_method}." end end |
#matches?(fakeweb) ⇒ Boolean
Indication of whether there’s a match on the URI from given requests.
23 24 25 26 27 28 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 23 def matches?(fakeweb) !FakeWeb::Registry.instance.requests.detect { |req| method, url = args_split(*req) match_method(method) && url == @url }.nil? end |
#negative_failure_message ⇒ String
Failure message if the URI should not have been requested.
46 47 48 49 50 51 52 |
# File 'lib/fake_web_matcher/request_matcher.rb', line 46 def if @method == :any "The URL #{@url} was requested and should not have been." else "The URL #{@url} was requested using #{formatted_method} and should not have been." end end |