|
| 1 | +Feature: have_enqueued_mail matcher |
| 2 | + |
| 3 | + The `have_enqueued_mail` (also aliased as `enqueue_mail`) matcher is used to check if given mailer was enqueued. |
| 4 | + |
| 5 | + Background: |
| 6 | + Given active job is available |
| 7 | + |
| 8 | + Scenario: Checking mailer class and method name |
| 9 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 10 | + """ruby |
| 11 | + require "rails_helper" |
| 12 | +
|
| 13 | + RSpec.describe NotificationsMailer do |
| 14 | + it "matches with enqueued mailer" do |
| 15 | + ActiveJob::Base.queue_adapter = :test |
| 16 | + expect { |
| 17 | + NotificationsMailer.signup.deliver_later |
| 18 | + }.to have_enqueued_mail(NotificationsMailer, :signup) |
| 19 | + end |
| 20 | + end |
| 21 | + """ |
| 22 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 23 | + Then the examples should all pass |
| 24 | + |
| 25 | + Scenario: Checking mailer enqueued time |
| 26 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 27 | + """ruby |
| 28 | + require "rails_helper" |
| 29 | +
|
| 30 | + RSpec.describe NotificationsMailer do |
| 31 | + it "matches with enqueued mailer" do |
| 32 | + ActiveJob::Base.queue_adapter = :test |
| 33 | + expect { |
| 34 | + NotificationsMailer.signup.deliver_later(:wait_until => Date.tomorrow.noon) |
| 35 | + }.to have_enqueued_mail(NotificationsMailer, :signup).at(Date.tomorrow.noon) |
| 36 | + end |
| 37 | + end |
| 38 | + """ |
| 39 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 40 | + Then the examples should all pass |
| 41 | + |
| 42 | + Scenario: Checking mailer enqueued with no wait |
| 43 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 44 | + """ruby |
| 45 | + require "rails_helper" |
| 46 | +
|
| 47 | + RSpec.describe NotificationsMailer do |
| 48 | + it "matches with enqueued mailer" do |
| 49 | + ActiveJob::Base.queue_adapter = :test |
| 50 | + expect { |
| 51 | + NotificationsMailer.signup.deliver_later |
| 52 | + }.to have_enqueued_mail(NotificationsMailer, :signup).at(:no_wait) |
| 53 | + end |
| 54 | + end |
| 55 | + """ |
| 56 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 57 | + Then the examples should all pass |
| 58 | + |
| 59 | + Scenario: Using alias method |
| 60 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 61 | + """ruby |
| 62 | + require "rails_helper" |
| 63 | +
|
| 64 | + RSpec.describe NotificationsMailer do |
| 65 | + it "matches with enqueued mailer" do |
| 66 | + ActiveJob::Base.queue_adapter = :test |
| 67 | + expect { |
| 68 | + NotificationsMailer.signup.deliver_later |
| 69 | + }.to enqueue_mail(NotificationsMailer, :signup) |
| 70 | + end |
| 71 | + end |
| 72 | + """ |
| 73 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 74 | + Then the examples should all pass |
0 commit comments