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

Some tests rely on a local DNS setup #107

Closed
lucaskanashiro opened this issue Jul 2, 2020 · 4 comments
Closed

Some tests rely on a local DNS setup #107

lucaskanashiro opened this issue Jul 2, 2020 · 4 comments

Comments

@lucaskanashiro
Copy link

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.

@kinduff
Copy link

kinduff commented Jan 25, 2021

@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

@hallelujah
Copy link
Owner

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

@arturoherrero
Copy link

@hallelujah We can also close this issue after #125 😉

@hallelujah
Copy link
Owner

Closing as solved

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

No branches or pull requests

4 participants