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

Add Test coverage for Hash arguments #59

Merged
merged 2 commits into from
Sep 29, 2017
Merged

Conversation

seanpdoyle
Copy link
Collaborator

Closes #58.

The match_response_schema can be chained off expect({ ... }) calls,
so add test coverage to ensure that.

end

it "validates when the schema matches" do
expect({ "id" => 1 }).to match_response_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.

"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 passed a Hash" 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.

@@ -22,6 +22,25 @@
expect(response_for({})).not_to match_response_schema("foo_schema")
end

context "when passed a Hash" 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.

Closes [#58].

The `match_response_schema` can be chained off `expect({ ... })` calls,
so add test coverage to ensure that.

[#58]: #58
@jsmestad
Copy link

@seanpdoyle so yes the success case requires no code change. It is the failure case that #58 addresses. The failure matcher calls pretty_json on both expect and actual values which fails if the actual is already a Hash.

@seanpdoyle
Copy link
Collaborator Author

@jsmestad aha! I understand. Thanks for clarifying.

})

expect {
expect({ "id" => "1" }).to match_response_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.

"additionalProperties" => false,
})

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.


it "fails with message when negated" 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.

end

it "fails with message when negated" 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.

"additionalProperties" => false,
})

expect({ "id" => 1 }).to match_response_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.

@jsmestad
Copy link

@seanpdoyle no problem! glad to help 👍

Thanks again for putting this gem together

@seanpdoyle seanpdoyle merged commit 69110c2 into master Sep 29, 2017
@@ -15,6 +15,8 @@ def to_s
def extract_json_string(payload)
if payload.respond_to?(:body)
payload.body
elsif payload.respond_to?(:to_h)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanpdoyle I didn't notice you changed the logic here from my #58 PR. This fails if the payload is an Array, which as a #to_h method on it.

With a payload.is_a?(Hash) check from my PR things pass fine.

With the change here in 0.7.1:

    Failure/Error: expect(payload).to match_response_schema('homes')

     TypeError:
       wrong element type Hash at 0 (expected array)

Example of what data is coming through as "payload" in this case (mock data):

[{"updated"=>"2017-12-08", "uuid"=>"0987623-1f4c-4a9d-8462-f873gd7c766sb"}, {"updated"=>"2017-08-02", "uuid"=>"abc12345-1f4c-4a9d-8462-18664247652c"}]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pull down #61 and try it out?

seanpdoyle added a commit that referenced this pull request Oct 3, 2017
Closes [#60]

Add support for an Array matcher argument similar to [Hash matcher
arguments][#59].

[#59]: #59
[#60]: #60
@seanpdoyle seanpdoyle deleted the add-support-for-hashes branch March 16, 2018 17:53
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.

None yet

3 participants