File: json_schema_test.rb

package info (click to toggle)
ruby-brandur-json-schema 0.19.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 376 kB
  • sloc: ruby: 3,764; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "test_helper"

require "json_schema"

describe JsonSchema do
  describe ".parse" do
    it "succeeds" do
      schema, errors = JsonSchema.parse(schema_sample)
      assert schema
      assert_nil errors
    end

    it "returns errors on a parsing problem" do
      pointer("#/properties").merge!(
        "app" => 4
      )
      schema, errors = JsonSchema.parse(schema_sample)
      refute schema
      assert_includes errors.map { |e| e.type }, :schema_not_found
    end
  end

  describe ".parse!" do
    it "succeeds on .parse!" do
      assert JsonSchema.parse!(schema_sample)
    end

    it "returns errors on a parsing problem" do
      pointer("#/properties").merge!(
        "app" => 4
      )
      e = assert_raises(JsonSchema::AggregateError) do
        JsonSchema.parse!(schema_sample)
      end
      assert_includes e.message, %{4 is not a valid schema.}
    end
  end

  def pointer(path)
    JsonPointer.evaluate(schema_sample, path)
  end

  def schema_sample
    @schema_sample ||= DataScaffold.schema_sample
  end
end