valid_email icon indicating copy to clipboard operation
valid_email copied to clipboard

Some tests rely on a local DNS setup

Open lucaskanashiro opened this issue 4 years ago • 3 comments

Some tests are failing when they are executed in a sandbox environment because they try to perform some MX records lookup which requires access to some kind of DNS setup. I faced this issue while trying to build the Debian package in the Ubuntu infrastructure, the failing tests are (full build log here):

Failed examples:

rspec './spec/email_validator_spec.rb[1:4:1:2:1]' # EmailValidator Translating in english behaves like Validating emails validating email with MX and fallback to A passes when email domain has MX record
rspec './spec/email_validator_spec.rb[1:4:1:2:2]' # EmailValidator Translating in english behaves like Validating emails validating email with MX and fallback to A passes when email domain has no MX record but has an A record
rspec './spec/email_validator_spec.rb[1:4:1:3:1]' # EmailValidator Translating in english behaves like Validating emails validating email with MX passes when email domain has MX record
rspec './spec/email_validator_spec.rb[1:5:1:2:1]' # EmailValidator Translating in french behaves like Validating emails validating email with MX and fallback to A passes when email domain has MX record
rspec './spec/email_validator_spec.rb[1:5:1:2:2]' # EmailValidator Translating in french behaves like Validating emails validating email with MX and fallback to A passes when email domain has no MX record but has an A record
rspec './spec/email_validator_spec.rb[1:5:1:3:1]' # EmailValidator Translating in french behaves like Validating emails validating email with MX passes when email domain has MX record
rspec ./spec/validate_email_spec.rb:25 # ValidateEmail.valid? when mx: true option passed returns true when mx record exist

As you can see all of them are related to MX record and the lookup needs to succeed (the other tests, which expect failures, pass). Maybe find a way to mock those MX records lookup and make the tests self contained is a good move.

lucaskanashiro avatar Jul 02 '20 18:07 lucaskanashiro

@lucaskanashiro I ended up stubbing the MxValidator for all the tests:

# rails_helper.rb

RSpec.configure do |config|
  config.before do
    allow_any_instance_of(MxValidator).to receive(:validate_each) { true }
  end
end

kinduff avatar Jan 25 '21 13:01 kinduff

Yes you are right. It might be better to have a either a dnsmasq or a Ruby name server setup for mocking our tests.

hallelujah avatar Feb 22 '21 20:02 hallelujah

@hallelujah We can also close this issue after https://github.com/hallelujah/valid_email/pull/125 😉

arturoherrero avatar Oct 04 '23 13:10 arturoherrero

Closing as solved

hallelujah avatar May 21 '24 13:05 hallelujah