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.
-
#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.
Instance Method Summary collapse
- #custom_matcher? ⇒ Boolean
-
#initialize(http_method:, route:, response_code: 200, response_body: '', headers: {}, default: false, matcher: ALWAYS_TRUE_MATCHER, schema: nil) ⇒ StaticRequestMatcher
constructor
A new instance of StaticRequestMatcher.
- #matches?(request) ⇒ Boolean
- #overridden! ⇒ Object
- #overridden? ⇒ Boolean
- #record_request(request) ⇒ Object
- #requests ⇒ Object
- #reset! ⇒ Object
- #to_s ⇒ Object
Methods inherited from BaseMatcher
#match_on_body?, #readonly?, #response
Constructor Details
#initialize(http_method:, route:, response_code: 200, response_body: '', headers: {}, default: false, matcher: ALWAYS_TRUE_MATCHER, schema: nil) ⇒ StaticRequestMatcher
Returns a new instance of StaticRequestMatcher.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 9 def initialize(http_method:, route:, response_code: 200, response_body: '', headers: {}, default: false, matcher: ALWAYS_TRUE_MATCHER, schema: nil) @default = default @matcher = matcher @headers = headers @response_body = response_body @response_code = response_code @route = route @http_method = http_method @schema = schema end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def default @default end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def headers @headers end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def http_method @http_method end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def matcher @matcher end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def response_body @response_body end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def response_code @response_code end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def route @route end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 7 def schema @schema end |
Instance Method Details
#custom_matcher? ⇒ Boolean
24 25 26 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 24 def custom_matcher? matcher != ALWAYS_TRUE_MATCHER end |
#matches?(request) ⇒ Boolean
20 21 22 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 20 def matches?(request) request.path == route && request.request_method == http_method && matcher.call(request) end |
#overridden! ⇒ Object
28 29 30 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 28 def overridden! @overridden = true end |
#overridden? ⇒ Boolean
32 33 34 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 32 def overridden? !!@overridden end |
#record_request(request) ⇒ Object
50 51 52 53 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 50 def record_request(request) request.body.rewind requests.push(RecordedRequest.new(body: request.body.read, request_env: request.env)) end |
#requests ⇒ Object
40 41 42 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 40 def requests @requests ||= [] end |
#reset! ⇒ Object
36 37 38 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 36 def reset! @overridden = false end |
#to_s ⇒ Object
44 45 46 47 48 |
# File 'lib/api_sim/matchers/static_request_matcher.rb', line 44 def to_s " \#{http_method} \#{route} -> (\#{response_code}) \#{response_body[0..20]}...\n DOC\nend\n".gsub(/^\s+/, '') |