-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feature rspec failed with reason #281
base: master
Are you sure you want to change the base?
Conversation
cd6e328
to
8ab2319
Compare
8ab2319
to
9aa3c43
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.
Thanks!
Left some suggestions in the comments.
case reason | ||
when nil | ||
next | ||
when Hash | ||
next if subject.reasons.details == reason | ||
when Symbol | ||
next if subject.reasons.details.values.flatten.any? { |h| h.include?(reason) } | ||
when String | ||
next if subject.reasons.respond_to?(:full_messages) && subject.reasons.full_messages.flatten.include?(reason) | ||
else | ||
raise TypeError, "unexpected reason: #{reason.inspect}" | ||
end |
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 would leave only the Hash matching option but add support for RSpec compound matchers instead:
failed "some desription", reason: a_hash_inclusing(no_admin: true)
For that, we only need to change the order and the ==
for ===
:
reason === subject.reasons.details
Partial and especially nested matching seems a bit off; if we unit-test policies, we must take care of the actual shape.
I18n is also out of scope, IMO.
What is the purpose of this pull request?
As suggested in this discussion #271, it allows to match reasons when using RSpec DSL
PR checklist: