From 84994b9f9e6588761cb0190256b973c041a71ee3 Mon Sep 17 00:00:00 2001 From: Vladislav Trotsenko Date: Wed, 19 Jan 2022 12:46:55 +0200 Subject: [PATCH] Technical/Update gem development dependencies (#197) * Added truemail integration tests * Added Truemail::DnsHelper#dns_mock_records_by_email, tests * Updated gem development dependencies * Updated CircleCI config * Updated gem version, changelog --- .circleci/config.yml | 10 +++++- CHANGELOG.md | 8 +++++ lib/truemail/version.rb | 2 +- spec/support/config/smtp_mock.rb | 7 ++++ spec/support/helpers/dns_helper.rb | 7 ++++ spec/support/helpers/dns_helper_spec.rb | 23 +++++++++++++ spec/truemail_spec.rb | 44 ++++++++++++++++--------- truemail.gemspec | 7 ++-- 8 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 spec/support/config/smtp_mock.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index 4b5a9da..735ef98 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,6 +27,12 @@ references: paths: - vendor/bundle + system_dependencies: &system_dependencies + run: + name: Installing system requirements + command: | + bundle exec smtp_mock -s -i ~ + install_codeclimate_reporter: &install_codeclimate_reporter run: name: Installing CodeClimate test reporter @@ -68,6 +74,7 @@ jobs: - <<: *restore_bundle_cache - <<: *bundle_install - <<: *save_bundle_cache + - <<: *system_dependencies - <<: *install_codeclimate_reporter - run: @@ -100,9 +107,10 @@ jobs: steps: - checkout - ruby/install-deps: - bundler-version: "2.3.3" + bundler-version: "2.3.5" with-cache: false path: './vendor/custom_bundle' + - <<: *system_dependencies - run: name: Running compatibility tests command: bundle exec rspec diff --git a/CHANGELOG.md b/CHANGELOG.md index e74e346..2850a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.6.2] - 2022.01.19 + +### Updated + +- Updated tests +- Updated gem development dependencies +- Updated gem version + ## [2.6.1] - 2022.01.04 ### Fixed diff --git a/lib/truemail/version.rb b/lib/truemail/version.rb index 7f91383..eb5472c 100644 --- a/lib/truemail/version.rb +++ b/lib/truemail/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Truemail - VERSION = '2.6.1' + VERSION = '2.6.2' end diff --git a/spec/support/config/smtp_mock.rb b/spec/support/config/smtp_mock.rb new file mode 100644 index 0000000..d65434a --- /dev/null +++ b/spec/support/config/smtp_mock.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'smtp_mock/test_framework/rspec' + +RSpec.configure do |config| + config.include SmtpMock::TestFramework::RSpec::Helper +end diff --git a/spec/support/helpers/dns_helper.rb b/spec/support/helpers/dns_helper.rb index 5a98273..9ecda17 100644 --- a/spec/support/helpers/dns_helper.rb +++ b/spec/support/helpers/dns_helper.rb @@ -7,5 +7,12 @@ module DnsHelper def dns_mock_gateway ["#{Truemail::DnsHelper::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"] end + + def dns_mock_records_by_email(email, dimension: 1) + mx_records = ::Array.new(dimension) { random_domain_name } + a_records = ::Array.new(dimension) { [Truemail::DnsHelper::LOCALHOST_IP_ADDRESS] } + mx_records_dns_mock = mx_records.zip(a_records).to_h.transform_values { |value| { a: value } } + { domain_from_email(email) => { mx: mx_records } }.merge(mx_records_dns_mock) + end end end diff --git a/spec/support/helpers/dns_helper_spec.rb b/spec/support/helpers/dns_helper_spec.rb index 0dcea86..3e93b40 100644 --- a/spec/support/helpers/dns_helper_spec.rb +++ b/spec/support/helpers/dns_helper_spec.rb @@ -10,4 +10,27 @@ expect(dns_mock_gateway).to eq(["#{described_class::LOCALHOST_IP_ADDRESS}:#{dns_mock_server.port}"]) end end + + describe '#dns_mock_records_by_email' do + let(:email) { 'user@domain.com' } + let(:email_domain) { 'domain.com' } + let(:mx_domain) { 'mx.example.com' } + + before { allow(FFaker::Internet).to receive(:domain_name).and_return(mx_domain) } + + specify do + dns_mock_records = dns_mock_records_by_email(email) + expect(dns_mock_records.dig(email_domain, :mx).size).to eq(1) + expect(dns_mock_records).to eq( + email_domain => { mx: [mx_domain] }, + mx_domain => { a: [Truemail::DnsHelper::LOCALHOST_IP_ADDRESS] } + ) + end + + specify do + expect( + dns_mock_records_by_email(email, dimension: 2).dig(email_domain, :mx).size + ).to eq(2) + end + end end diff --git a/spec/truemail_spec.rb b/spec/truemail_spec.rb index 99c82fa..c5496ec 100644 --- a/spec/truemail_spec.rb +++ b/spec/truemail_spec.rb @@ -146,27 +146,39 @@ before do described_class.configure do |config| config.verifier_email = 'admin@bestweb.com.ua' - config.connection_timeout = 1 - config.response_timeout = 1 + config.dns = dns_mock_gateway + # config.smtp_port = smtp_mock_server.port # TODO: should be refactored with smtp-mock server in next release end end include_examples 'returns validator instance' - # TODO: should be refactored with smtp-mock server in next release - # describe 'integration tests' do - # context 'when checks real email' do - # specify do - # expect(described_class.validate('admin@bestweb.com.ua').result.valid?).to be(true) - # end - # end - - # context 'when checks fake email' do - # specify do - # expect(described_class.validate('nonexistent_email@bestweb.com.ua').result.valid?).to be(false) - # end - # end - # end + describe 'integration tests' do + let(:target_email) { random_email } + let(:dns_mock_records) { dns_mock_records_by_email(target_email, dimension: 2) } + + before do + dns_mock_server.assign_mocks(dns_mock_records) + smtp_mock_server(**smtp_mock_server_options) + stub_const('Truemail::Validate::Smtp::Request::SMTP_PORT', smtp_mock_server.port) + end + + context 'when checks real email' do + let(:smtp_mock_server_options) { {} } + + specify do + expect(described_class.validate(target_email).result).to be_valid + end + end + + context 'when checks fake email' do + let(:smtp_mock_server_options) { { not_registered_emails: [target_email] } } + + specify do + expect(described_class.validate(target_email).result).not_to be_valid + end + end + end end context 'when custom configuration passed' do diff --git a/truemail.gemspec b/truemail.gemspec index b06dc94..71cf99c 100644 --- a/truemail.gemspec +++ b/truemail.gemspec @@ -35,7 +35,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'simpleidn', '~> 0.2.1' spec.add_development_dependency 'bundler-audit', '~> 0.9.0.1' - spec.add_development_dependency 'dns_mock', '~> 1.4', '>= 1.4.4' + spec.add_development_dependency 'dns_mock', '~> 1.5' spec.add_development_dependency 'fasterer', '~> 0.9.0' spec.add_development_dependency 'ffaker', '~> 2.20' spec.add_development_dependency 'json_matchers', '~> 0.11.1' @@ -44,10 +44,11 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6' spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.6' spec.add_development_dependency 'rspec', '~> 3.10' - spec.add_development_dependency 'rubocop', '~> 1.24' - spec.add_development_dependency 'rubocop-performance', '~> 1.13' + spec.add_development_dependency 'rubocop', '~> 1.24', '>= 1.24.1' + spec.add_development_dependency 'rubocop-performance', '~> 1.13', '>= 1.13.2' spec.add_development_dependency 'rubocop-rspec', '~> 2.7' spec.add_development_dependency 'simplecov', '~> 0.17.1' + spec.add_development_dependency 'smtp_mock', '~> 0.1.1' spec.add_development_dependency 'truemail-rspec', '~> 0.7.0' spec.add_development_dependency 'webmock', '~> 3.14' end