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

New matcher that asserts presence of the given fields #35

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AlexanderPavlenko
Copy link

No description provided.

@@ -25,6 +26,10 @@ def have_json_type(type)
def have_json_size(size)
JsonSpec::Matchers::HaveJsonSize.new(size)
end

def have_json_fields(size)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be fields rather than size, right?

@laserlemon
Copy link
Contributor

Please reference #25 to see what I'd like to see in order to pull this in. Thank you!

@AlexanderPavlenko
Copy link
Author

@laserlemon check out latest commit

@inossidabile
Copy link

@laserlemon are there any other problems with this pr? :)

@AlexanderPavlenko
Copy link
Author

@charlierudolph nice catch, fixed

@laserlemon
Copy link
Contributor

@AlexanderPavlenko Thanks for all of your work! There are just a couple things I would change and I'll comment on those individually in the diff. Thank you again!


Scenario: Base paths
When I get the JSON
Then the JSON should have keys "a, b, c"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since "a, b, c" is a valid JSON key, we should separate each key out into its own quotes:

Then the JSON should have keys "a", "b", "c"

Copy link
Author

Choose a reason for hiding this comment

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

@@ -70,6 +70,16 @@
end
end

Then /^the (?:JSON|json)(?: response)?(?: at "(.*)")? should( not)? have the following keys:$/ do |base, negative, table|
match = have_json_keys(table.raw)
match = match.at_path(base) if base

Choose a reason for hiding this comment

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

Please rename base to path to be consistent.
Can then shorten to one line as its works if path is nil.

match = have_json_keys(table.raw).at_path(path)

Nice drying up. Will make use of this pattern to dry up the rest of cucumber later.

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.

4 participants