class ApiSim::Matchers::RequestBodyMatcher
Attributes
default[R]
headers[R]
http_method[R]
matcher[R]
query[R]
response_body[R]
response_code[R]
route[R]
schema[R]
Public Class Methods
new(http_method:, route:, response_code: 200, response_body: '', headers: {}, default: false, body_matches:, schema: nil)
click to toggle source
# File lib/api_sim/matchers/request_body_matcher.rb, line 10 def initialize(http_method:, route:, response_code: 200, response_body: '', headers: {}, default: false, body_matches:, schema: nil) @default = default @matcher = Regexp.compile(body_matches) @headers = headers @response_body = response_body @response_code = response_code @route = Mustermann.new(route) @http_method = http_method @schema = schema end
Public Instance Methods
match_on_body?()
click to toggle source
# File lib/api_sim/matchers/request_body_matcher.rb, line 28 def match_on_body? true end
matches?(request)
click to toggle source
# File lib/api_sim/matchers/request_body_matcher.rb, line 21 def matches?(request) request.body.rewind body = request.body.read request.body.rewind route.match(request.path) && request.request_method == http_method && matcher.match(body) end
to_s()
click to toggle source
# File lib/api_sim/matchers/request_body_matcher.rb, line 32 def to_s <<-DOC.gsub(/^\s+/, '') #{http_method} #{route} /#{matcher.source}/ -> (#{response_code}) #{response_body[0..20]}... DOC end