File: have_json_path.rb

package info (click to toggle)
ruby-json-spec 1.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ruby: 1,059; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 669 bytes parent folder | download | duplicates (4)
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