Class: ApiSim::Matchers::StaticRequestMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- ApiSim::Matchers::StaticRequestMatcher
- Defined in:
- lib/api_sim/matchers/static_request_matcher.rb
Constant Summary
Constants inherited from BaseMatcher
BaseMatcher::ALWAYS_TRUE_MATCHER, BaseMatcher::DEFAULT_RACK_RESPONSE
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#initialize(**args) ⇒ StaticRequestMatcher
constructor
A new instance of StaticRequestMatcher.
- #matches?(request) ⇒ Boolean
- #overridden! ⇒ Object
- #overridden? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from BaseMatcher
#custom_matcher?, #match_on_body?, #readonly?, #record_request, #requests, #reset!, #response
Constructor Details
#initialize(**args) ⇒ StaticRequestMatcher
Returns a new instance of StaticRequestMatcher.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 10 def initialize(**args) @default = args.fetch(:default, false) @matcher = args.fetch(:matcher, ALWAYS_TRUE_MATCHER) @headers = args.fetch(:headers, {}) @response_body = args.fetch(:response_body, '') @response_code = args.fetch(:response_code, 200) route, @query = args.fetch(:route).split('?') @query ||= args.fetch(:query, '') @route = Mustermann.new(route) @http_method = args.fetch(:http_method) @schema = args.fetch(:schema, nil) @request_schema = args.fetch(:request_schema, nil) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def default @default end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def headers @headers end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def http_method @http_method end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def matcher @matcher end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def query @query end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def response_body @response_body end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def response_code @response_code end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def route @route end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
8 9 10 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 8 def schema @schema end |
Instance Method Details
#matches?(request) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 24 def matches?(request) matches_route_pattern?(request) && (query.empty? ? true : request.query_string == query) && request.request_method == http_method && matcher.call(request) end |
#overridden! ⇒ Object
31 32 33 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 31 def overridden! @overridden = true end |
#overridden? ⇒ Boolean
35 36 37 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 35 def overridden? !!@overridden end |
#to_s ⇒ Object
39 40 41 42 43 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 39 def to_s <<-DOC.gsub(/^\s+/, '') #{http_method} #{route} -> (#{response_code}) #{response_body[0..20]}... DOC end |