Skip to content

Commit

Permalink
Technical/Migrate to Ruby 2.7.x syntax (#91)
Browse files Browse the repository at this point in the history
* Updated Truemail::Configuration#logger=
* Updated gem dependencies
* Updated gem documentation
* Updated linters configs
  • Loading branch information
bestwebua authored Sep 21, 2020
1 parent 63e96be commit 8977763
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-0-89
channel: rubocop-0-91

reek:
enabled: true
1 change: 1 addition & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ detectors:
- Truemail::Validate::Mx#a_record
- Truemail::Audit::Base#verifier_domain
- Truemail::Configuration#domain_matcher
- Truemail::Configuration#logger_options
- Truemail::Log::Serializer::Base#errors

ControlParameter:
Expand Down
39 changes: 39 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ Style/SlicingWithRange:
Style/StringConcatenation:
Enabled: true

Style/CombinableLoops:
Enabled: true

Style/KeywordParametersOrder:
Enabled: true

Style/RedundantSelfAssignment:
Enabled: true

Style/SoleNestedConditional:
Enabled: true

Layout/LineLength:
Max: 140

Expand Down Expand Up @@ -131,6 +143,9 @@ Layout/SpaceAroundMethodCallOperator:
Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Layout/BeginEndAlignment:
Enabled: true

Lint/NonDeterministicRequireOrder:
Enabled: false

Expand Down Expand Up @@ -176,6 +191,27 @@ Lint/TopLevelReturnWithArgument:
Lint/UnreachableLoop:
Enabled: true

Lint/ConstantDefinitionInBlock:
Enabled: true

Lint/DuplicateRequire:
Enabled: true

Lint/EmptyFile:
Enabled: true

Lint/IdentityComparison:
Enabled: true

Lint/TrailingCommaInAttributeDeclaration:
Enabled: true

Lint/UselessMethodDefinition:
Enabled: true

Lint/UselessTimes:
Enabled: true

Performance/AncestorsInclude:
Enabled: true

Expand All @@ -200,6 +236,9 @@ Performance/Squeeze:
Performance/StringInclude:
Enabled: true

Performance/Sum:
Enabled: true

RSpec/ExampleLength:
Enabled: false

Expand Down
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

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).

## [1.9.1] - 2020.09.21

### Changed

Migrated to updated Ruby 2.7.x syntax.

- Updated `Truemail::Configuration#logger=`

## [1.9.0] - 2020.09.01

## Added
### Added

- Ability to use `Truemail::Auditor` instance represented as json directly
- `Truemail::Log::Serializer::AuditorJson`
Expand Down Expand Up @@ -42,7 +50,7 @@ Truemail.host_audit.as_json

## [1.8.0] - 2020.06.21

## Added
### Added

Separated audit features for verifier host.

Expand Down Expand Up @@ -89,7 +97,7 @@ Truemail.host_audit

## [1.7.1] - 2020.05.10

## Added
### Added

- Ability to show `not_rfc_mx_lookup_flow` attribute in serialized validation result

Expand Down Expand Up @@ -137,7 +145,7 @@ Truemail.validate('nonexistent_email@bestweb.com.ua').as_json

## [1.7.0] - 2020.05.09

## Added
### Added

- Ability to use not RFC MX lookup flow (MX and Null MX records will be checked on the DNS validation layer only)

Expand Down
27 changes: 14 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
truemail (1.9.0)
truemail (1.9.1)
simpleidn (~> 0.1.1)

GEM
Expand Down Expand Up @@ -48,7 +48,7 @@ GEM
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
psych (~> 3.1.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (1.7.1)
regexp_parser (1.8.0)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand All @@ -63,25 +63,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rubocop (0.89.1)
rubocop (0.91.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.3.0, < 1.0)
rubocop-ast (>= 0.4.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
rubocop-ast (0.4.2)
parser (>= 2.7.1.4)
rubocop-performance (1.7.1)
rubocop (>= 0.82.0)
rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
rubocop-ast (>= 0.4.0)
rubocop-rspec (1.43.2)
rubocop (~> 0.87)
ruby-progressbar (1.10.1)
ruby_parser (3.14.2)
ruby_parser (3.15.0)
sexp_processor (~> 4.9)
sexp_processor (4.15.0)
sexp_processor (4.15.1)
simplecov (0.17.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -90,7 +91,7 @@ GEM
simpleidn (0.1.1)
unf (~> 0.1.4)
thor (1.0.1)
truemail-rspec (0.2.0)
truemail-rspec (0.2.1)
rspec (~> 3.9)
truemail (~> 1.4, >= 1.4.1)
unf (0.1.4)
Expand All @@ -112,12 +113,12 @@ DEPENDENCIES
rake (~> 13.0, >= 13.0.1)
reek (~> 6.0, >= 6.0.1)
rspec (~> 3.9)
rubocop (~> 0.89.1)
rubocop-performance (~> 1.7, >= 1.7.1)
rubocop (~> 0.91.0)
rubocop-performance (~> 1.8, >= 1.8.1)
rubocop-rspec (~> 1.43, >= 1.43.2)
simplecov (~> 0.17.1)
truemail!
truemail-rspec (~> 0.2.0)
truemail-rspec (~> 0.2.1)

BUNDLED WITH
1.16.6
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Vladislav Trotsenko
Copyright (c) 2019-2020 Vladislav Trotsenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS and SMTP. Be sure that email address valid and exists.

> Actual and maintainable documentation :books: for developers is living [here](https://truemail-rb.org/truemail-gem).
## Table of Contents

- [Synopsis](#synopsis)
Expand Down Expand Up @@ -53,7 +55,6 @@ Configurable framework agnostic plain Ruby email validator. Verify email via Reg
- [Credits](#credits)
- [Versioning](#versioning)
- [Changelog](CHANGELOG.md)
- [Developers Documentation](https://truemail-rb.org/truemail-gem/)

## Synopsis

Expand Down
8 changes: 7 additions & 1 deletion lib/truemail/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Configuration
DEFAULT_RESPONSE_TIMEOUT = 2
DEFAULT_CONNECTION_ATTEMPTS = 2
DEFAULT_VALIDATION_TYPE = :smtp
DEFAULT_LOGGER_OPTIONS = { tracking_event: :error, stdout: false, log_absolute_path: nil }.freeze

attr_reader :email_pattern,
:smtp_error_body_pattern,
Expand Down Expand Up @@ -71,7 +72,8 @@ def validation_type_for=(settings)
end
end

def logger=(tracking_event: :error, stdout: false, log_absolute_path: nil)
def logger=(options)
tracking_event, stdout, log_absolute_path = logger_options(options)
valid_event = Truemail::Log::Event::TRACKING_EVENTS.key?(tracking_event)
stdout_only = stdout && log_absolute_path.nil?
file_only = log_absolute_path.is_a?(String)
Expand Down Expand Up @@ -140,5 +142,9 @@ def validate_validation_type(settings)
check_validation_type(validation_type)
end
end

def logger_options(current_options)
Truemail::Configuration::DEFAULT_LOGGER_OPTIONS.merge(current_options).values
end
end
end
2 changes: 1 addition & 1 deletion lib/truemail/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def punycode_email

attr_reader :validation_type

def initialize(email, with: nil, configuration:)
def initialize(email, configuration:, with: nil)
with ||= configuration.default_validation_type
raise Truemail::ArgumentError.new(with, :argument) unless Truemail::Validator::VALIDATION_TYPES.include?(with)
@result = Truemail::Validator::Result.new(email: email, configuration: configuration)
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 = '1.9.0'
VERSION = '1.9.1'
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
rspec_custom = File.join(File.dirname(__FILE__), 'support/**/*.rb')
Dir[File.expand_path(rspec_custom)].each { |file| require file unless file[/\A.+_spec\.rb\z/] }

RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
RSpec.configure do |config|
config.include Truemail::RSpec
config.example_status_persistence_file_path = '.rspec_status'
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers/generate_email_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Truemail
class GenerateEmailHelper
def self.call(**options)
new(options).call
new(**options).call
end

def initialize(size: :auto, symbols: %w[- _ . +], invalid_email_with: [])
Expand Down
30 changes: 25 additions & 5 deletions spec/truemail/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,31 @@

let(:valid_email) { FFaker::Internet.email }

describe 'defined constants' do
specify { expect(described_class).to be_const_defined(:DEFAULT_CONNECTION_TIMEOUT) }
specify { expect(described_class).to be_const_defined(:DEFAULT_RESPONSE_TIMEOUT) }
specify { expect(described_class).to be_const_defined(:DEFAULT_CONNECTION_ATTEMPTS) }
specify { expect(described_class).to be_const_defined(:DEFAULT_VALIDATION_TYPE) }
describe 'class constants' do
context 'DEFAULT_CONNECTION_TIMEOUT' do
specify { expect(described_class).to be_const_defined(:DEFAULT_CONNECTION_TIMEOUT) }
specify { expect(described_class::DEFAULT_CONNECTION_TIMEOUT).to eq(2) }
end

context 'DEFAULT_RESPONSE_TIMEOUT' do
specify { expect(described_class).to be_const_defined(:DEFAULT_RESPONSE_TIMEOUT) }
specify { expect(described_class::DEFAULT_CONNECTION_TIMEOUT).to eq(2) }
end

context 'DEFAULT_CONNECTION_ATTEMPTS' do
specify { expect(described_class).to be_const_defined(:DEFAULT_CONNECTION_ATTEMPTS) }
specify { expect(described_class::DEFAULT_CONNECTION_TIMEOUT).to eq(2) }
end

context 'DEFAULT_VALIDATION_TYPE' do
specify { expect(described_class).to be_const_defined(:DEFAULT_VALIDATION_TYPE) }
specify { expect(described_class::DEFAULT_VALIDATION_TYPE).to eq(:smtp) }
end

context 'DEFAULT_LOGGER_OPTIONS' do
specify { expect(described_class).to be_const_defined(:DEFAULT_LOGGER_OPTIONS) }
specify { expect(described_class::DEFAULT_LOGGER_OPTIONS).to eq(tracking_event: :error, stdout: false, log_absolute_path: nil) }
end
end

describe '.new' do
Expand Down
2 changes: 1 addition & 1 deletion spec/truemail/validator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Truemail::Validator do
subject(:validator_instance) { described_class.new(email, options) }
subject(:validator_instance) { described_class.new(email, **options) }

let(:email) { FFaker::Internet.email }
let(:configuration_instance) { create_configuration }
Expand Down
29 changes: 15 additions & 14 deletions spec/truemail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,28 @@
context 'when global configuration successfully set' do
before do
described_class.configure do |config|
config.verifier_email = 'valdyslav.trotsenko@rubygarage.org'
config.verifier_email = 'admin@bestweb.com.ua'
config.connection_timeout = 1
config.response_timeout = 1
end
end

include_examples 'returns validator instance'

describe 'integration tests' do
context 'when checks real email' do
specify do
expect(described_class.validate('vladyslav.trotsenko@rubygarage.org').result.valid?).to be(true)
end
end

context 'when checks fake email' do
specify do
expect(described_class.validate('nonexistent_email@rubygarage.org').result.valid?).to be(false)
end
end
end
# 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
end

context 'when custom configuration passed' do
Expand Down
Loading

0 comments on commit 8977763

Please sign in to comment.