Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Regex match failure on refute_email_delivered_with/2 #645

Open
Stamates opened this issue Sep 9, 2022 · 1 comment
Open

Fix Regex match failure on refute_email_delivered_with/2 #645

Stamates opened this issue Sep 9, 2022 · 1 comment

Comments

@Stamates
Copy link

Stamates commented Sep 9, 2022

We often have dynamic content (and emojis) in the subject line of emails such that we normally use a Regex pattern match.
Example:
assert_email_delivered_with(subject: ~r/Request/)

As a testing pattern, we'll have a second test that is expected to NOT send the same email based on other failing conditions. For test readability, it would be great to just use refute_email_delivered_with(subject: ~r/Request/), unfortunately, that returns the following error:

** (FunctionClauseError) no function clause matching in Regex.match?/2

The following arguments were given to Regex.match?/2:

   # 1
   ~r/Request/

   # 2
   nil

Attempted function clauses (showing 1 out of 1):
   def match?(%Regex{} = regex, string) when is_binary(string)

code: refute_email_delivered_with(subject: ~r/Request/)
stacktrace:
     (elixir 1.13.4) lib/regex.ex:282: Regex.match?/2
     (elixir 1.13.4) lib/enum.ex:3973: Enum.any_list/2

I believe this is due to a bug in the refute_email_delivered_with function:
The received_email_params is being set to [] if no email is sent, but the if check is is_nil(received_email_params) which will be false instead of true like it should be if no email was sent. This causes else condition to be called which results in a failure because [][:some_key] == nil.

The same Regex error occurs if you try to refute_email_delivered_with using an invalid email key when an email is actually received. Seems like the solve might be adding do_match(nil, _, _), do: refute false as a first function head (if we expect providing an invalid email key for refute_email_delivered_with to pass when an email is delivered).

Copy link
Contributor

This issue has been automatically marked as "stale:discard". We are sorry that we haven't been able to prioritize it yet.
If this issue still relevant, please leave any comment if you have any new additional information that helps to solve this issue. We encourage you to create a pull request, if you can. We are happy to help you with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant