Module: SchemaTest::Minitest

Defined in:
lib/schema_test/minitest.rb

Instance Method Summary collapse

Instance Method Details

#assert_json_schema_validates_against(json, schema) ⇒ Object



24
25
26
27
# File 'lib/schema_test/minitest.rb', line 24

def assert_json_schema_validates_against(json, schema)
  errors = SchemaTest.validate_json(json, schema)
  assert errors.empty?, "JSON did not pass schema:\n#{errors.join("\n")}"
end

#assert_valid_json_for_schema(json, name, version:, schema: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/schema_test/minitest.rb', line 5

def assert_valid_json_for_schema(json, name, version:, schema: nil)
  install_assert_api_expansion_hook

  definition = SchemaTest::Definition.find(name, version)
  raise "Unknown definition #{name}, version: #{version}" unless definition.present?

  expected_schema = definition.as_json_schema

  if schema != expected_schema
    if ENV['CI']
      flunk "Outdated API schema assertion at #{caller[0]}"
    else
      queue_write_expanded_assert_api_call(caller[0], __method__, name, version, expected_schema)
    end
  end

  assert_json_schema_validates_against(json, expected_schema)
end