-
-
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
Add Test coverage for Hash arguments #59
Conversation
end | ||
|
||
it "validates when the schema matches" do | ||
expect({ "id" => 1 }).to match_response_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.
"id" => { "type" => "number" }, | ||
}, | ||
"additionalProperties" => false, | ||
}) |
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.
context "when passed a Hash" do | ||
before(:each) 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.
@@ -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", { |
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.
3047721
to
bf5f19e
Compare
@seanpdoyle so yes the success case requires no code change. It is the failure case that #58 addresses. The failure matcher calls |
@jsmestad aha! I understand. Thanks for clarifying. |
}) | ||
|
||
expect { | ||
expect({ "id" => "1" }).to match_response_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.
"additionalProperties" => false, | ||
}) | ||
|
||
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.
"id" => { "type" => "number" }, | ||
}, | ||
"additionalProperties" => false, | ||
}) |
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.
|
||
it "fails with message when negated" 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.
end | ||
|
||
it "fails with message when negated" 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.
"additionalProperties" => false, | ||
}) | ||
|
||
expect({ "id" => 1 }).to match_response_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.
@seanpdoyle no problem! glad to help 👍 Thanks again for putting this gem together |
@@ -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) |
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.
@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"}]
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.
Could you pull down #61 and try it out?
Closes #58.
The
match_response_schema
can be chained offexpect({ ... })
calls,so add test coverage to ensure that.