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

Relax expectations for flash messages in tests #16889

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

cbliard
Copy link
Member

@cbliard cbliard commented Oct 3, 2024

Ticket

None

Follow up to #16789 (this comment) and #16863.

What are you trying to accomplish?

Make the test code more intentional when we want to be precise with flash messages, and less verbose when we just want to dismiss them, the flash helpers do not have implicit values for :type and :message anymore, and do not require them to be present either.

What approach did you choose and why?

Previously expect_flash default value for type was :success, meaning that code like expect_flash(message: "An error occurred") implicitly expected a :success flash, which is not obvious by reading the code.

This commit changes the default value for type to :any for all flash helpers, so that there is no implicit expectations on the flash type anymore. expect_flash(message: "An error occurred") would then check the flash message text and only the flash message text, which is a fair expectation.

Additionally, it also relaxes the expectation on the message text so that expect_and_dismiss_flash and other helpers can be called without :type or :message parameters, and it will be done regardless of the flash type and message text.

Finally it also adds documentation to all flash helpers.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

From https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraspecificactions:

> This cop is deprecated. We plan to remove this in the next major
> version update to 3.0.
To make the test code more intentional when we want to
be precise with flash messages, and less verbose when we just want to
dismiss them, the flash helpers do not have implicit values for `:type`
and `:message` anymore, and do not require them to be present either.

Previously `expect_flash` default value for `type` was `:success`,
meaning that code like `expect_flash(message: "An error occurred")`
implicitly expected a `:success` flash, which is not obvious by reading
the code.

This commit changes the default value for `type` to `:any` for all flash
helpers, so that there is no implicit expectations on the flash type
anymore.

Additionally, it also relaxes the expectation on the message text so
that `expect_and_dismiss_flash` and other helpers can be called without
`:type` or `:message` parameters, and it will be done regardless of the
flash type and message text.

Finally it also adds documentation to all flash helpers.
@oliverguenther
Copy link
Member

I'm not sure why you would want to expect a flash, but not it's type. This should be part of the test?

@cbliard
Copy link
Member Author

cbliard commented Oct 4, 2024

I'm not sure why you would want to expect a flash, but not it's type. This should be part of the test?

Good question. I think I remember some times where I added an expectation on the flash for synchronization, and I had to indicate the type but that was not my purpose. I just wanted to discard any flash. But maybe my memories are wrong and that's not useful and your initial PR should be preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants