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

Feature rspec failed with reason #281

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

Conversation

inkstak
Copy link
Contributor

@inkstak inkstak commented Dec 11, 2024

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:

  • Tests included
  • Documentation updated
  • Changelog entry added

@inkstak inkstak force-pushed the feature-rspec_failed_with_reason branch from cd6e328 to 8ab2319 Compare December 11, 2024 10:38
@inkstak inkstak force-pushed the feature-rspec_failed_with_reason branch from 8ab2319 to 9aa3c43 Compare December 11, 2024 10:48
@inkstak inkstak marked this pull request as ready for review December 11, 2024 10:49
Copy link

Coverage Status

coverage: 93.681% (-0.1%) from 93.782%
when pulling 9aa3c43 on inkstak:feature-rspec_failed_with_reason
into 14add12 on palkan:master.

Copy link
Owner

@palkan palkan left a 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.

Comment on lines +89 to +100
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
Copy link
Owner

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.

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.

2 participants