Skip to content

Commit

Permalink
Technical/Update gem development dependencies (#197)
Browse files Browse the repository at this point in the history
* Added truemail integration tests
* Added Truemail::DnsHelper#dns_mock_records_by_email, tests
* Updated gem development dependencies
* Updated CircleCI config
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Jan 19, 2022
1 parent d593924 commit 84994b9
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 21 deletions.
10 changes: 9 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +74,7 @@ jobs:
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
- <<: *system_dependencies
- <<: *install_codeclimate_reporter

- run:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Truemail
VERSION = '2.6.1'
VERSION = '2.6.2'
end
7 changes: 7 additions & 0 deletions spec/support/config/smtp_mock.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/support/helpers/dns_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions spec/support/helpers/dns_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { '[email protected]' }
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
44 changes: 28 additions & 16 deletions spec/truemail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,39 @@
before do
described_class.configure do |config|
config.verifier_email = '[email protected]'
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('[email protected]').result.valid?).to be(true)
# end
# end

# context 'when checks fake email' do
# specify do
# expect(described_class.validate('[email protected]').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
Expand Down
7 changes: 4 additions & 3 deletions truemail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

0 comments on commit 84994b9

Please sign in to comment.