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
Allow count constraint on include
matcher
#1168
Conversation
47d17de
to
993e363
Compare
993e363
to
7d7374d
Compare
ebd6738
to
e7fd3ab
Compare
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.
Awesome!
# @api private | ||
# Asbtract class to implement `once`, `at_least` and other | ||
# count constraints. | ||
class CountExpectation < BaseMatcher |
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.
👏 I took a stab at this in the past, but your implementation is superior by all means.
My aim was to reuse it in rspec-mocks
's recieve
, do you think it's doable in theory by making it an includable module? rspec-mocks
don't depend on rspec-expectations
, and rspec-support
doesn't seem to be a good place for CountExpectation
.
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.
I looked at receive
first too and got discouraged as the implementation is more complex, needs to care about block passing, deals with other constraints, etc. and it wasn't in the same gem. When I realized I could use yield
's code, that was simple.
I agree, all of that code could be using the same implementation, although in practice it's not clear if there would be that much gain.
I first used a module BTW, but yard seemed to have issues with the module having an initialize
method so instead went with a class.
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.
I've seen this code being repeated in custom matchers quite a lot. E.g. https://github.com/zverok/saharspec/blob/master/lib/saharspec/matchers/send_message.rb#L31
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.
Should I turn it into a module? Probably should avoid initialize
altogether if it's to be made publicly and rely on attr_reader
s I imagine
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.
Maybe add attr_reader
for count_expectation_type
/count_expected_count
? They would default to nil
and that would make it possible to get rid of initialize
.
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.
Just for the reference WIP.
ea43fa1
to
c9efca0
Compare
ab65187
to
ac62d6f
Compare
Looks good to me. |
ac62d6f
to
42e80b3
Compare
👋 I've had a brief look over this, but delayed reviewing in depth because I knew I wanted to support combination constraints on the yield matcher that would have knock on effects. Could you rebase / rejig this so it works with support that combination? If you have the time I'd love to see the logic from yield pulled out into something thats used by the other matchers with composition rather than inheritance... |
Sounds good. I'll be busy for the next few days but will ping when I push the updated PR |
Another matcher that might benefit from the extraction https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/matchers/active_job.rb#L167 |
11584b1
to
2e314ee
Compare
Refactored a bit & rebased. |
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.
Awesome! ⚡️
2e314ee
to
05a0622
Compare
@JonRowe mind taking another look? |
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.
LGTM. I find the code, clean and self documented. Good job @marcandre. 🙌🏻
@JonRowe ? |
Ping @JonRowe |
Add the aria-describedby id to the select_all_that_apply field as it broke WAVE testing of aria tags Turn the select_all_that_apply field to a hint text to standardise with other pages such as the identify_types_of_outgoings page Fix duplication of error messages under the select_all_that_apply hint because it's already in the error summary above the title. This is only when checkboxes are checked and nested values cause an error on submission. It still shows an error underneath it for when no checkboxes were selected validation fails Test the above. However, keep an eye on rspec/rspec-expectations#1168 which is an rspec matcher coming soon that allows to test how many times something has been seen in a response body.
Add the aria-describedby id to the select_all_that_apply field as it broke WAVE testing of aria tags Turn the select_all_that_apply field to a hint text to standardise with other pages such as the identify_types_of_outgoings page Fix duplication of error messages under the select_all_that_apply hint because it's already in the error summary above the title. This is only when checkboxes are checked and nested values cause an error on submission. It still shows an error underneath it for when no checkboxes were selected validation fails Test the above. However, keep an eye on rspec/rspec-expectations#1168 which is an rspec matcher coming soon that allows to test how many times something has been seen in a response body.
Add the aria-describedby id to the select_all_that_apply field as it broke WAVE testing of aria tags for the savings and investments page and other assets page. Fix duplication of error messages under the select_all_that_apply hint because it's already in the error summary above the title. This is only when checkboxes are checked and nested values cause an error on submission. It still shows an error underneath it for when no checkboxes were selected validation fails Test the above. However, keep an eye on rspec/rspec-expectations#1168 which is an rspec matcher coming soon that allows to test how many times something has been seen in a response body.
Add the aria-describedby id to the select_all_that_apply field as it broke WAVE testing of aria tags for the savings and investments page and other assets page. Fix duplication of error messages under the select_all_that_apply hint because it's already in the error summary above the title. This is only when checkboxes are checked and nested values cause an error on submission. It still shows an error underneath it for when no checkboxes were selected validation fails Test the above. However, keep an eye on rspec/rspec-expectations#1168 which is an rspec matcher coming soon that allows to test how many times something has been seen in a response body.
Add the aria-describedby id to the select_all_that_apply field as it broke WAVE testing of aria tags for the savings and investments page and other assets page. Fix duplication of error messages under the select_all_that_apply hint because it's already in the error summary above the title. This is only when checkboxes are checked and nested values cause an error on submission. It still shows an error underneath it for when no checkboxes were selected validation fails Test the above. However, keep an eye on rspec/rspec-expectations#1168 which is an rspec matcher coming soon that allows to test how many times something has been seen in a response body.
05a0622
to
d708270
Compare
Rebased, just to be sure. @JonRowe could this be merged please? |
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.
One outstanding query, but it's not a blocker.
Thank you! 👏 I understand that you're scratching your own itch to allow |
This allows to specify how many times an element should be included:
Note: Not implemented for
include(1, 2, 3)
nor for hash cases.Also: This PR build on #1167.