Module: ActiveModelSerializers::Test::Schema

Defined in:
lib/active_model_serializers/test/schema.rb

Defined Under Namespace

Classes: AssertResponseSchema

Constant Summary

MissingSchema =
Class.new(Errno::ENOENT)
InvalidSchemaError =
Class.new(StandardError)

Instance Method Summary (collapse)

Instance Method Details

- (Boolean, Minitest::Assertion) assert_response_schema(schema_path = nil, message = nil)

A Minitest Assertion that test the response is valid against a schema.

Examples:

get :index
assert_response_schema

Parameters:

  • schema_path (String) (defaults to: nil)

    a custom schema path

  • message (String) (defaults to: nil)

    a custom error message

Returns:

  • (Boolean)

    true when the response is valid

  • (Minitest::Assertion)

    when the response is invalid



12
13
14
15
# File 'lib/active_model_serializers/test/schema.rb', line 12

def assert_response_schema(schema_path = nil, message = nil)
  matcher = AssertResponseSchema.new(schema_path, response, message)
  assert(matcher.call, matcher.message)
end