File: have_json_path_spec.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 (29 lines) | stat: -rw-r--r-- 833 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
require "spec_helper"

describe JsonSpec::Matchers::HaveJsonPath do
  it "matches hash keys" do
    %({"one":{"two":{"three":4}}}).should have_json_path("one/two/three")
  end

  it "doesn't match values" do
    %({"one":{"two":{"three":4}}}).should_not have_json_path("one/two/three/4")
  end

  it "matches array indexes" do
    %([1,[1,2,[1,2,3,4]]]).should have_json_path("1/2/3")
  end

  it "respects null array values" do
    %([null,[null,null,[null,null,null,null]]]).should have_json_path("1/2/3")
  end

  it "matches hash keys and array indexes" do
    %({"one":[1,2,{"three":4}]}).should have_json_path("one/2/three")
  end

  it "provides a description message" do
    matcher = have_json_path("json")
    matcher.matches?(%({"id":1,"json":"spec"}))
    matcher.description.should == %(have JSON path "json")
  end
end