We’ve just submitted a PR to hopefully improve the assert_enqueued_email_with
method. This makes the passing of parameterized mailer parameters and mailer method arguments explicit. It contains some other goodness and updated docs. I would love some feedback!
Args
TestHelperMailer.test_args("some_email", "some_name").deliver_later
matches
assert_enqueued_email_with TestHelperMailer, :test_args, args: ["some_email", "some_name"]
Params
TestHelperMailer.with(all: "good").test_parameter_args.deliver_later
matches
assert_enqueued_email_with TestHelperMailer, :test_parameter_args, args: { all: "good" }
Named Args
TestHelperMailer.test_named_args(email: "some_email", name: "some_name").deliver_later
matches
assert_enqueued_email_with TestHelperMailer, :test_named_args, args: [{ email: "some_email", name: "some_name" }]
Params and Args
TestHelperMailer.with(all: "good").test_args("some_email", "some_name").deliver_later
matches
assert_enqueued_email_with TestHelperMailer, :test_args, params: { all: "good" }, args: ["some_email", "some_name"]
Parameterized Mailer
TestHelperMailer.with(all: "good").test_parameter_args.deliver_later
matches
assert_enqueued_email_with TestHelperMailer.with(all: "good"), :test_parameter_args
That last scenario is questionable, but I think beautiful and readable.