class Dalziel::Matchers::JSONPatternMatcher

Attributes

body[R]
json_expression[R]
request[R]

Public Class Methods

new(json_expression) click to toggle source
# File lib/dalziel.rb, line 81
def initialize(json_expression)
  @json_expression = json_expression
end

Public Instance Methods

does_not_match?(*) click to toggle source
# File lib/dalziel.rb, line 85
def does_not_match?(*)
  fail "Inverted matching is not implemented with this matcher"
end
failure_message() click to toggle source
# File lib/dalziel.rb, line 98
def failure_message
  if @not_parsable_json
    original = Dalziel.indent(@original.inspect)
    error = "#{@not_parsable_json.class}: #{@not_parsable_json}"
    "Couldn't parse the following:\n\n%s\n\n%s" % [ original, error ]
  else
    json = Dalziel.indent(JSON.pretty_generate(@hash))
    type = @original.is_a?(String) ? "JSON" : @original.class.to_s
    "Got the following %s:\n\n%s\n\n%s" % [ type, json, matcher.last_error ]
  end
end
matches?(json) click to toggle source
# File lib/dalziel.rb, line 89
def matches?(json)
  @original = json
  @hash = json.is_a?(String) ? JSON.parse(json) : json
  matcher =~ @hash
rescue JSON::ParserError => error
  @not_parsable_json = error
  false
end

Private Instance Methods

matcher() click to toggle source
# File lib/dalziel.rb, line 112
def matcher
  @matcher ||= JsonExpressions::Matcher.new(json_expression)
end