|
| 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 | + @rails_post_5 |
| 9 | + Scenario: Checking mailer class and method name |
| 10 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 11 | + """ruby |
| 12 | + require "rails_helper" |
| 13 | +
|
| 14 | + RSpec.describe NotificationsMailer do |
| 15 | + it "matches with enqueued mailer" do |
| 16 | + ActiveJob::Base.queue_adapter = :test |
| 17 | + expect { |
| 18 | + NotificationsMailer.signup.deliver_later |
| 19 | + }.to have_enqueued_mail(NotificationsMailer, :signup) |
| 20 | + end |
| 21 | + end |
| 22 | + """ |
| 23 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 24 | + Then the examples should all pass |
| 25 | + |
| 26 | + @rails_post_5 |
| 27 | + Scenario: Checking mailer enqueued time |
| 28 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 29 | + """ruby |
| 30 | + require "rails_helper" |
| 31 | +
|
| 32 | + RSpec.describe NotificationsMailer do |
| 33 | + it "matches with enqueued mailer" do |
| 34 | + ActiveJob::Base.queue_adapter = :test |
| 35 | + expect { |
| 36 | + NotificationsMailer.signup.deliver_later(:wait_until => Date.tomorrow.noon) |
| 37 | + }.to have_enqueued_mail(NotificationsMailer, :signup).at(Date.tomorrow.noon) |
| 38 | + end |
| 39 | + end |
| 40 | + """ |
| 41 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 42 | + Then the examples should all pass |
| 43 | + |
| 44 | + @rails_post_5 |
| 45 | + Scenario: Checking mailer enqueued with no wait |
| 46 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 47 | + """ruby |
| 48 | + require "rails_helper" |
| 49 | +
|
| 50 | + RSpec.describe NotificationsMailer do |
| 51 | + it "matches with enqueued mailer" do |
| 52 | + ActiveJob::Base.queue_adapter = :test |
| 53 | + expect { |
| 54 | + NotificationsMailer.signup.deliver_later |
| 55 | + }.to have_enqueued_mail(NotificationsMailer, :signup).at(:no_wait) |
| 56 | + end |
| 57 | + end |
| 58 | + """ |
| 59 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 60 | + Then the examples should all pass |
| 61 | + |
| 62 | + @rails_post_5 |
| 63 | + Scenario: Using alias method |
| 64 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 65 | + """ruby |
| 66 | + require "rails_helper" |
| 67 | +
|
| 68 | + RSpec.describe NotificationsMailer do |
| 69 | + it "matches with enqueued mailer" do |
| 70 | + ActiveJob::Base.queue_adapter = :test |
| 71 | + expect { |
| 72 | + NotificationsMailer.signup.deliver_later |
| 73 | + }.to enqueue_mail(NotificationsMailer, :signup) |
| 74 | + end |
| 75 | + end |
| 76 | + """ |
| 77 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 78 | + Then the examples should all pass |
| 79 | + |
| 80 | + @rails_pre_5 |
| 81 | + Scenario: Checking mailer class and method name |
| 82 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 83 | + """ruby |
| 84 | + require "rails_helper" |
| 85 | +
|
| 86 | + RSpec.describe Notifications do |
| 87 | + it "matches with enqueued mailer" do |
| 88 | + ActiveJob::Base.queue_adapter = :test |
| 89 | + expect { |
| 90 | + Notifications.signup.deliver_later |
| 91 | + }.to have_enqueued_mail(Notifications, :signup) |
| 92 | + end |
| 93 | + end |
| 94 | + """ |
| 95 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 96 | + Then the examples should all pass |
| 97 | + |
| 98 | + @rails_pre_5 |
| 99 | + Scenario: Checking mailer enqueued time |
| 100 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 101 | + """ruby |
| 102 | + require "rails_helper" |
| 103 | +
|
| 104 | + RSpec.describe Notifications do |
| 105 | + it "matches with enqueued mailer" do |
| 106 | + ActiveJob::Base.queue_adapter = :test |
| 107 | + expect { |
| 108 | + Notifications.signup.deliver_later(:wait_until => Date.tomorrow.noon) |
| 109 | + }.to have_enqueued_mail(Notifications, :signup).at(Date.tomorrow.noon) |
| 110 | + end |
| 111 | + end |
| 112 | + """ |
| 113 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 114 | + Then the examples should all pass |
| 115 | + |
| 116 | + @rails_pre_5 |
| 117 | + Scenario: Checking mailer enqueued with no wait |
| 118 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 119 | + """ruby |
| 120 | + require "rails_helper" |
| 121 | +
|
| 122 | + RSpec.describe Notifications do |
| 123 | + it "matches with enqueued mailer" do |
| 124 | + ActiveJob::Base.queue_adapter = :test |
| 125 | + expect { |
| 126 | + Notifications.signup.deliver_later |
| 127 | + }.to have_enqueued_mail(Notifications, :signup).at(:no_wait) |
| 128 | + end |
| 129 | + end |
| 130 | + """ |
| 131 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 132 | + Then the examples should all pass |
| 133 | + |
| 134 | + @rails_pre_5 |
| 135 | + Scenario: Using alias method |
| 136 | + Given a file named "spec/mailers/user_mailer_spec.rb" with: |
| 137 | + """ruby |
| 138 | + require "rails_helper" |
| 139 | +
|
| 140 | + RSpec.describe Notifications do |
| 141 | + it "matches with enqueued mailer" do |
| 142 | + ActiveJob::Base.queue_adapter = :test |
| 143 | + expect { |
| 144 | + Notifications.signup.deliver_later |
| 145 | + }.to enqueue_mail(Notifications, :signup) |
| 146 | + end |
| 147 | + end |
| 148 | + """ |
| 149 | + When I run `rspec spec/mailers/user_mailer_spec.rb` |
| 150 | + Then the examples should all pass |
0 commit comments