-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure matcher to record_errors
#52
Conversation
|
||
expect(response_for({ "id" => 1, "title" => "bar" })). | ||
to match_response_schema("foo_schema") | ||
expect(response_for({ "id" => 1 })). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
}, | ||
}) | ||
|
||
expect(response_for({ "id" => 1, "title" => "bar" })). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
"id" => { "type" => "number" }, | ||
"title" => { "type" => "string" }, | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent the right brace the same as the first position after the preceding left parenthesis.
config.options.delete(:strict) | ||
with_options(strict: true) do | ||
create_schema("foo_schema", { | ||
"type" => "object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
JsonMatchers.configure do |config| | ||
config.options.delete(:strict) | ||
with_options(strict: true) do | ||
create_schema("foo_schema", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
2c686ee
to
ee46320
Compare
}) | ||
invalid_payload = response_for({ "username" => "foo" }) | ||
|
||
expect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using {...} for multi-line blocks.
} | ||
} | ||
}) | ||
invalid_payload = response_for({ "username" => "foo" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
] | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent the right brace the same as the first position after the preceding left parenthesis.
{ "minLength": 5 } | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
{ "type": "string" }, | ||
{ "minLength": 5 } | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
"allOf": [ | ||
{ "type": "string" }, | ||
{ "minLength": 5 } | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
"username" => { | ||
"allOf": [ | ||
{ "type": "string" }, | ||
{ "minLength": 5 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline array.
|
||
expect(response_for({})).not_to match_response_schema("foo_schema") | ||
create_schema("foo_schema", { | ||
"type" => "object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
"required" => ["foo"]) | ||
|
||
expect(response_for({})).not_to match_response_schema("foo_schema") | ||
create_schema("foo_schema", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
}) | ||
invalid_payload = response_for({ "username" => "foo" }) | ||
|
||
expect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using {...} for multi-line blocks.
} | ||
} | ||
}) | ||
invalid_payload = response_for({ "username" => "foo" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
] | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent the right brace the same as the first position after the preceding left parenthesis.
{ "minLength": 5 } | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
{ "type": "string" }, | ||
{ "minLength": 5 } | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
"allOf": [ | ||
{ "type": "string" }, | ||
{ "minLength": 5 } | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline hash.
"username" => { | ||
"allOf": [ | ||
{ "type": "string" }, | ||
{ "minLength": 5 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last item of a multiline array.
|
||
expect(response_for({})).not_to match_response_schema("foo_schema") | ||
create_schema("foo_schema", { | ||
"type" => "object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
"required" => ["foo"]) | ||
|
||
expect(response_for({})).not_to match_response_schema("foo_schema") | ||
create_schema("foo_schema", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Closes [#51]. By default, `JsonMatchers.configuration.options[:record_errors] = true`. Extract `JsonMatchers::Validator` to encapsulate error reporting behavior. `JSON::Validator` exposes a `#validate!` method that will raise on validation failures, and a `#fully_validate!` method that won't raise, but will return an array of error messages instead. [#51]: #51
ee46320
to
ee1349d
Compare
Can you clarify why this should be configurable? |
By default, the underlying Validator will raise an error when passed invalid JSON. Unfortunately, this error tends to be high-level and vague. When configured with This feels like a reasonable default, so this PR makes it so. |
Your question raises a good point: since it's now the default, should we support Before this set of PRs, we'd forward along the configuration options (like Since it is now the default, do you think we should explicitly remove support for |
I think so? Or: when would I ever set it to |
I am not sure of that. As a solution, we could outright ignore the What do you think? |
+1 to removing this as configuration. I want my matcher to always record errors. |
Ensure that validation is always configured with `record_errors: true`, based on the following [comments]: > By default, the underlying Validator will raise an error when passed > invalid JSON. Unfortunately, this error tends to be high-level and > [vague](#51). > When configured with `record_errors: true`, the validator will collect > and return an array of error messages instead of raising. > This feels like a [reasonable > default](#51 (comment)), > so this PR makes it so. [comments]: #52 (comment)
Ensure that validation is always configured with `record_errors: true`, based on the following [comments]: > By default, the underlying Validator will raise an error when passed > invalid JSON. Unfortunately, this error tends to be high-level and > [vague](#51). > When configured with `record_errors: true`, the validator will collect > and return an array of error messages instead of raising. > This feels like a [reasonable > default](#51 (comment)), > so this PR makes it so. [comments]: #52 (comment)
Closes #51.
By default,
JsonMatchers.configuration.options[:record_errors] = true
.Extract
JsonMatchers::Validator
to encapsulate error reportingbehavior.
JSON::Validator
exposes a#validate!
method that will raise onvalidation failures, and a
#fully_validate!
method that won't raise,but will return an array of error messages instead.
Additionally, this commit introduces the
#with_options
test helperthat scopes configuration options to a given test block.