-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept timeout option in test helpers (#605)
What changed? ============ We update all test helpers in `Bamboo.Test` to accept a `:timeout` option. Once we get the timeout, we forward it to ExUnit's `assert_receive` as the second argument. Refutation helpers will use the `timeout` option passed in (if any), and then fallback to 100ms (if not in shared mode) or the configured `refute_timeout` if on `shared_mode`.
- Loading branch information
Showing
2 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,14 @@ defmodule Bamboo.TestAdapterTest do | |
|
||
assert_delivered_email(%{email | assigns: :assigns_removed_for_testing}) | ||
end | ||
|
||
test "accepts timeout" do | ||
email = new_email(from: "[email protected]", to: "[email protected]") | ||
|
||
email |> TestMailer.deliver_now() | ||
|
||
assert_delivered_email(email, timeout: 1) | ||
end | ||
end | ||
|
||
describe "refute_delivered_email/1" do | ||
|
@@ -142,6 +150,12 @@ defmodule Bamboo.TestAdapterTest do | |
refute_delivered_email(sent_email) | ||
end | ||
end | ||
|
||
test "accepts a timeout configuration" do | ||
unsent_email = new_email(from: "[email protected]") | ||
|
||
refute_delivered_email(unsent_email, timeout: 1) | ||
end | ||
end | ||
|
||
describe "assert_email_delivered_with/1" do | ||
|
@@ -216,6 +230,14 @@ defmodule Bamboo.TestAdapterTest do | |
assert_email_delivered_with(text_body: ~r/tea/) | ||
end | ||
end | ||
|
||
test "accepts timeout" do | ||
email = new_email(from: "[email protected]", to: "[email protected]") | ||
|
||
email |> TestMailer.deliver_now() | ||
|
||
assert_email_delivered_with([from: "[email protected]"], timeout: 1) | ||
end | ||
end | ||
|
||
describe "refute_email_delivered_with/1" do | ||
|
@@ -259,6 +281,14 @@ defmodule Bamboo.TestAdapterTest do | |
refute_email_delivered_with(text_body: ~r/coffee/) | ||
end | ||
end | ||
|
||
test "accepts a timeout configuration" do | ||
mail = new_email(to: [nil: "[email protected]"], from: {nil, "[email protected]"}) | ||
|
||
TestMailer.deliver_now(mail) | ||
|
||
refute_email_delivered_with([to: [nil: "[email protected]"]], timeout: 1) | ||
end | ||
end | ||
|
||
describe "assert_no_emails_sent/0" do | ||
|
@@ -296,6 +326,15 @@ defmodule Bamboo.TestAdapterTest do | |
assert_no_emails_delivered() | ||
end | ||
end | ||
|
||
test "accepts a timeout configuration" do | ||
sent_email = new_email(from: "[email protected]", to: "whoever") | ||
sent_email |> TestMailer.deliver_now() | ||
|
||
assert_raise ExUnit.AssertionError, fn -> | ||
assert_no_emails_delivered(timeout: 1) | ||
end | ||
end | ||
end | ||
|
||
describe "assert_delivered_email_matches/1" do | ||
|
@@ -312,5 +351,13 @@ defmodule Bamboo.TestAdapterTest do | |
assert_delivered_email_matches(%{to: [{nil, email}]}) | ||
assert email == "[email protected]" | ||
end | ||
|
||
test "accepts timeout" do | ||
sent_email = new_email(from: "[email protected]", to: ["[email protected]"]) | ||
|
||
TestMailer.deliver_now(sent_email) | ||
|
||
assert_delivered_email_matches(%{to: [{nil, "[email protected]"}]}, timeout: 1) | ||
end | ||
end | ||
end |