Created
October 22, 2022 14:00
-
-
Save fullstackplus/6d3a334dedf548f26b79577e76062e66 to your computer and use it in GitHub Desktop.
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
require 'truemail' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
Truemail.configure do |config| | |
config.verifier_email = '[email protected]' | |
config.smtp_safe_check = true # setting to false makes SMTP validation fail | |
end | |
def valid?(email) | |
r = Truemail.validate(email, with: :regex) | |
m = Truemail.validate(email, with: :mx) | |
s = Truemail.validate(email) | |
r.result.success & | |
m.result.success & | |
s.result.success | |
end | |
GOOD = [ | |
# your legit email adresses go here | |
] | |
BAD = [ | |
# spam emails | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
# bogus email — makes the tests pass | |
"[email protected]" | |
] | |
describe "testing a set of random emails with Truemail" do | |
it "validates all good emails as good" do | |
good = GOOD.reduce(true) { |bool, addr| bool & valid?(addr) } | |
_(good).must_equal true | |
end | |
# all spam emails validate! | |
it "marks at least one spam email as bad" do | |
bad = BAD.reduce(true) { |bool, addr| bool & valid?(addr) } | |
_(bad).must_equal false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So this is me figuring out whether the Truemail gem (https://github.com/truemail-rb) also detects spam email addresses. Turns out, it does not. It only detects non-existing addresses. Add your emails to the test case above and see if all tests pass.