Skip to content
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

Fix error messages for string responses #49

Closed
wants to merge 1 commit into from

Conversation

sskylar
Copy link
Contributor

@sskylar sskylar commented Nov 7, 2016

While match_response_schema can now accept a string (thanks to #43), I noticed it will cause a NoMethodError in error messages:

NoMethodError:
  undefined method `body' for "{\"foo\":\"bar\"}":String

This fix checks if response respond_to?(:body) before attempting to call it from the error message. Included a test for failed string responses to ensure desired behavior.

Also fixed what I think is a related typo in README: match_json_schema should be match_response_schema, correct?

- include test for failed string response
- also fix `match_json_schema` typo in README (assuming this should be `match_response_schema`).
end

it "fails with message when negated" do
expect {

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.

"id" => { "type" => "number" },
},
"additionalProperties" => false,
})

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.

context "when JSON is a string" do
before(:each) do
create_schema("foo_schema", {
"type" => "object",

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.

})
context "when JSON is a string" do
before(:each) do
create_schema("foo_schema", {

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.

@seanpdoyle
Copy link
Collaborator

Released in https://github.com/thoughtbot/json_matchers/releases/tag/v0.6.3.

Thanks!

@seanpdoyle seanpdoyle closed this Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants