I’d like to extend ActionMailer::TestHelper#assert_enqueued_email_with
to allow the args
parameter to be set to a callable. This would allow it to be passed a Proc/lambda as a predicate, similar to the assert_enqueued_with
method.
The use case is I have a controller action that sends an email, but it is not possible to me to know the exact value of one of the arguments (it’s a randomly generated value), so it’s impossible for me to provide a value to args
that will satisfy the assertion. By allowing a Proc/lambda I can check the other args that I do know the values of, and also validate that the value I don’t know is at least in the correct format.
Example:
assert_enqueued_email_with MyMailer, :my_email, args: ->(args) { args[:known] == expected && args[:unkown].size == 6 } do
post send_email_path
end
I have a proof of concept here, I haven’t updated documentation or tests yet since I figured it would make sense to get approval first.
There’s also an open question of how this should handle args vs params. My proof of concept only supports params, but I assume that isn’t ideal. It seems odd to me that assert_enqueued_email_with
doesn’t have both an args
and params
parameter, maybe that would be something to investigate too.