File: 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,296 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::Schema do
  it "allows schema attribute access with #[]" do
    schema = JsonSchema::Schema.new
    schema.properties = { "foo" => nil }
    assert_equal({ "foo" => nil }, schema[:properties])
  end

  it "allows schema attribute access with #[] and overridden name" do
    schema = JsonSchema::Schema.new
    schema.additional_properties = { "foo" => nil }
    assert_equal({ "foo" => nil }, schema[:additionalProperties])
  end

  it "allows schema attribute access with #[] as string" do
    schema = JsonSchema::Schema.new
    schema.properties = { "foo" => nil }
    assert_equal({ "foo" => nil }, schema["properties"])
  end

  it "raises if attempting to access #[] with bad method" do
    schema = JsonSchema::Schema.new
    assert_raises NoMethodError do
      schema[:wat]
    end
  end

  it "raises if attempting to access #[] with non-schema attribute" do
    schema = JsonSchema::Schema.new
    assert_raises NoMethodError do
      schema[:expanded]
    end
  end

  it "updates type_parsed when type is changed" do
    schema = JsonSchema::Schema.new
    schema.type = ["integer"]
    assert_equal [Integer], schema.type_parsed

    schema.type = ["string"]
    assert_equal [String], schema.type_parsed
  end
end