Method: RSpec::Rails::Matchers#have_enqueued_mail

Defined in:
lib/rspec/rails/matchers/have_enqueued_mail.rb

#have_enqueued_mail(mailer_class = nil, mail_method_name = nil) ⇒ Object Also known as: have_enqueued_email, enqueue_mail, enqueue_email

Passes if an email has been enqueued inside block. May chain with to specify expected arguments. May chain at_least, at_most or exactly to specify a number of times. May chain at to specify a send time. May chain on_queue to specify a queue.

Examples:

expect {
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail

expect {
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail(MyMailer)

expect {
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail(MyMailer, :welcome)

# Using alias
expect {
  MyMailer.welcome(user).deliver_later
}.to enqueue_mail(MyMailer, :welcome)

expect {
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail(MyMailer, :welcome).with(user)

expect {
  MyMailer.welcome(user).deliver_later
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail(MyMailer, :welcome).at_least(:once)

expect {
  MyMailer.welcome(user).deliver_later
}.to have_enqueued_mail(MyMailer, :welcome).at_most(:twice)

expect {
  MyMailer.welcome(user).deliver_later(wait_until: Date.tomorrow.noon)
}.to have_enqueued_mail(MyMailer, :welcome).at(Date.tomorrow.noon)

expect {
  MyMailer.welcome(user).deliver_later(queue: :urgent_mail)
}.to have_enqueued_mail(MyMailer, :welcome).on_queue(:urgent_mail)


218
219
220
# File 'lib/rspec/rails/matchers/have_enqueued_mail.rb', line 218

def have_enqueued_mail(mailer_class = nil, mail_method_name = nil)
  HaveEnqueuedMail.new(mailer_class, mail_method_name)
end