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
Implement send_email matcher #2670
Conversation
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.
Nice!
A feature spec would be helpful to make this more discoverable. |
Thanks for this, it mostly looks great just some readability tweaks, I'm also wondering if theres a way to surface better the multiple email failure case especially as if you don't match say, subject, you could easily trigger it |
spec/support/shared_contexts.rb
Outdated
@@ -0,0 +1,9 @@ | |||
RSpec.shared_context "test mailer" do | |||
class TestMailer < ActionMailer::Base |
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 don't like this idea actually, Rubocop is right - https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ConstantDefinitionInBlock
Defining classes with let also complicates things.
Classes should be defined within modules. Moving it out to a shared module.
@JonRowe to address this point:
I have an idea to inspect the sent emails. 0e25b66 That should give a clue for devs where the failure comes from. Ideally, that would be great to inspect the body as well, but the output can be very huge. Therefore, I would better not do that. Basically, having just the subject inspected would suffice, but the other important attributes like from/to not hurt. |
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.
Looks great!
A few nitpicks below.
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.
Thank you so much for the idea and for implementing it!
@pirj can the failed CI job be restarted? looks like there was a network issue - https://github.com/rspec/rspec-rails/actions/runs/4790425603/jobs/8522781666?pr=2670 |
Green. It slipped my mind, do we squash commits in meaningful ones before merging? |
@pirj I've squashed them. |
@JonRowe all things are polished in my opinion, is there something else I can improve in this PR? |
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 a couple of wording tweaks to the feature, and this is good to go, sorry for the delayed review.
Merged in 69c09bc thanks for the hard work on this. |
Released in 6.1.0 apologies for the delay |
Currently, it already has a
have_enqueued_mail
matcher, but it's too low-level, requiring attention to details such as job name, mailer name, queue, and so on. While all of that information can be useful, from a business perspective, it's rarely necessary. This suggested matcher aims to improve the situation so that when you use it, you can focus on what matters, such as 'an email with a specific subject and specific text within the body being sent'.Examples:
Originally that was a gist: https://gist.github.com/ka8725/6053d55be74f15b53cabfc3ac4dc99df
A related LinkedIn post - https://www.linkedin.com/feed/update/urn:li:activity:6990304469477429248?utm_source=share&utm_medium=member_desktop
TODO