class Dalziel::Matchers::RequestMatcher
Attributes
body[R]
json_expression[R]
request[R]
Public Class Methods
new(json_expression)
click to toggle source
# File lib/dalziel.rb, line 122 def initialize(json_expression) @json_expression = json_expression end
Public Instance Methods
all_stubbed_requests()
click to toggle source
# File lib/dalziel.rb, line 168 def all_stubbed_requests WebMock::RequestRegistry.instance.requested_signatures end
does_not_match?(response)
click to toggle source
# File lib/dalziel.rb, line 145 def does_not_match?(response) fail "Inverted matching is not implemented with this matcher" end
failure_message()
click to toggle source
# File lib/dalziel.rb, line 149 def failure_message if @request.nil? || @request.empty? "No request matched" elsif !@is_json "Accept header is not JSON.\n\n%s\n\nAccept is %s" % [ show_request, @accept.inspect ] else "Request body did not match.\n\n%s\n\n%s" % [ show_request, payload_matcher.last_error ] end end
matches?(request_pattern)
click to toggle source
# File lib/dalziel.rb, line 126 def matches?(request_pattern) @request = nil all_stubbed_requests.each { |request_signature, _count| if request_pattern.matches?(request_signature) @request = request_signature break end } return false if @request.nil? @body = JSON.parse(@request.body) @accept = @request.headers["Accept"] @is_json = @accept =~ /\bjson$/ @json_match = payload_matcher =~ @body @is_json && @json_match end
payload_matcher()
click to toggle source
# File lib/dalziel.rb, line 164 def payload_matcher @payload_matcher ||= JsonExpressions::Matcher.new(json_expression) end
show_request()
click to toggle source
# File lib/dalziel.rb, line 159 def show_request headers = Dalziel.format_headers(request.headers) Dalziel.indent "%s %s\n\n%s\n\n%s" % [ request.method.to_s.upcase, request.uri.to_s, headers, JSON.pretty_generate(body) ] end