1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
module JsonSpec
module Matchers
class HaveJsonPath
include JsonSpec::Helpers
def initialize(path)
@path = path
end
def matches?(json)
parse_json(json, @path)
true
rescue JsonSpec::MissingPath
false
end
def failure_message
%(Expected JSON path "#{@path}")
end
alias :failure_message_for_should :failure_message
def failure_message_when_negated
%(Expected no JSON path "#{@path}")
end
alias :failure_message_for_should_not :failure_message_when_negated
def description
%(have JSON path "#{@path}")
end
end
end
end
|