According to the Rails documentation, the method assert_emails
allows to transform the syntax :
assert_difference ->{ ActionMailer::Base.deliveries.size }, +1 do
post :method_that_should_send_email
end
to
assert_emails 1 do
post :method_that_should_send_email
end
which I find much better, because I don't have to copy paste the long syntax every time.
However I get the following error in my controllers tests when using the above code:
NoMethodError: undefined method `assert_emails'
I assume this is because the method is only available in mailers tests.
Is there a way to make it available to controllers tests too? Is there a good reason why this is not available by default? Is there a better way to test that calling a specific route results in sending a email?
Thanks.
Rspec.describe
line – Illbred