NAME

Test::JSON::Schema::Acceptance - Acceptance testing for JSON-Schema based validators like JSON::Schema

VERSION

version 0.990

SYNOPSIS

This module allows the JSON Schema Test Suite tests to be used in perl to test a module that implements json-schema. These are the same tests that many modules (libraries, plugins, packages, etc.) use to confirm support of json-schema. Using this module to confirm support gives assurance of interoperability with other modules that run the same tests in different languages.

In the JSON::Schema module, a test could look like the following:

use Test::More;
use JSON::Schema;
use Test::JSON::Schema::Acceptance;

my $accepter = Test::JSON::Schema::Acceptance->new(3);

# Skip tests which are known not to be supported or which cause problems.
my $skip_tests = ['multiple extends', 'dependencies', 'ref'];

$accepter->acceptance( sub{
  my ( $schema, $input ) = @_;
  return JSON::Schema->new($schema)->validate($input);
}, {
  skip_tests => $skip_tests
} );

done_testing();

This would determine if JSON::Schema's validate method returns the right result for all of the cases in the JSON Schema Test Suite, except for those listed in $skip_tests.

DESCRIPTION

JSON Schema is an IETF draft (at time of writing) which allows you to define the structure of JSON.

The abstract from draft 4 of the specification:

    JSON Schema defines the media type "application/schema+json", a JSON based format for defining the structure of JSON data. JSON Schema provides a contract for what JSON data is required for a given application and how to interact with it. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.

JSON::Schema is a perl module created independently of the specification, which aims to implement the json-schema specification.

This module allows other perl modules (for example JSON::Schema) to test that they are json-schema compliant, by running the tests from the official test suite, without having to manually convert them to perl tests.

You are unlikely to want this module, unless you are attempting to write a module which implements json-schema the specification, and want to test your compliance.

CONSTRUCTOR

Test::JSON::Schema::Acceptance->new($schema_version)

Create a new instance of Test::JSON::Schema::Acceptance.

Accepts optional argument of $schema_version. This determines the draft version of the schema to confirm compliance to. Default is draft 4 (current), but in the synopsis example, JSON::Schema is testing draft 3 compliance.

SUBROUTINES/METHODS

acceptance

Accepts a sub and optional options in the form of a hash. The sub should return truthy or falsey depending on if the schema was valid for the input or not.

options

The only option which is currently accepted is skip_tests, which should be an array ref of tests you want to skip. You can skip a whole section of tests or individual tests. Any test name that contains any of the array refs items will be skipped, using grep. You can also skip a test by its number.

ACKNOWLEDGEMENTS

Daniel Perrett <perrettdl@cpan.org> for the concept and help in design.

Ricardo Signes <rjbs@cpan.org> for direction to and creation of Test::Fatal.

Various others in #perl-help.

SUPPORT

bugs may be submitted through https://github.com/karenetheridge/Test-JSON-Schema-Acceptance/issues.

AUTHOR

Ben Hutton (@relequestual) <relequest@cpan.org>

CONTRIBUTORS

  • Ben Hutton <bh7@sanger.ac.uk>

  • Karen Etheridge <ether@cpan.org>

  • Ben Hutton <relequestual@gmail.com>

  • Daniel Perrett <dp13@sanger.ac.uk>

COPYRIGHT AND LICENCE

This software is Copyright (c) 2015 by Ben Hutton.

This is free software, licensed under:

The MIT (X11) License