diff --git a/.codeclimate.yml b/.codeclimate.yml index 9ffb76c..42574a1 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -7,7 +7,7 @@ checks: plugins: rubocop: enabled: true - channel: rubocop-0-89 + channel: rubocop-0-91 reek: enabled: true diff --git a/.reek.yml b/.reek.yml index c8820db..46bc36e 100644 --- a/.reek.yml +++ b/.reek.yml @@ -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: diff --git a/.rubocop.yml b/.rubocop.yml index abc6338..6f05cc7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 @@ -131,6 +143,9 @@ Layout/SpaceAroundMethodCallOperator: Layout/EmptyLinesAroundAttributeAccessor: Enabled: true +Layout/BeginEndAlignment: + Enabled: true + Lint/NonDeterministicRequireOrder: Enabled: false @@ -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 @@ -200,6 +236,9 @@ Performance/Squeeze: Performance/StringInclude: Enabled: true +Performance/Sum: + Enabled: true + RSpec/ExampleLength: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 5474078..7bd4ec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` @@ -42,7 +50,7 @@ Truemail.host_audit.as_json ## [1.8.0] - 2020.06.21 -## Added +### Added Separated audit features for verifier host. @@ -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 @@ -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) diff --git a/Gemfile.lock b/Gemfile.lock index fb9453f..33df069 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - truemail (1.9.0) + truemail (1.9.1) simpleidn (~> 0.1.1) GEM @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/LICENSE.txt b/LICENSE.txt index eeb3b4f..e896313 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 diff --git a/README.md b/README.md index 737dc6d..f4e6283 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/lib/truemail/configuration.rb b/lib/truemail/configuration.rb index 5ba9e64..8c15a99 100644 --- a/lib/truemail/configuration.rb +++ b/lib/truemail/configuration.rb @@ -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, @@ -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) @@ -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 diff --git a/lib/truemail/validator.rb b/lib/truemail/validator.rb index 3d43ed5..91e0487 100644 --- a/lib/truemail/validator.rb +++ b/lib/truemail/validator.rb @@ -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) diff --git a/lib/truemail/version.rb b/lib/truemail/version.rb index 3d269fa..ab56fa4 100644 --- a/lib/truemail/version.rb +++ b/lib/truemail/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Truemail - VERSION = '1.9.0' + VERSION = '1.9.1' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7e9de42..c077107 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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' diff --git a/spec/support/helpers/generate_email_helper.rb b/spec/support/helpers/generate_email_helper.rb index cd0a107..56c3b44 100644 --- a/spec/support/helpers/generate_email_helper.rb +++ b/spec/support/helpers/generate_email_helper.rb @@ -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: []) diff --git a/spec/truemail/configuration_spec.rb b/spec/truemail/configuration_spec.rb index 06714d3..f51ab8a 100644 --- a/spec/truemail/configuration_spec.rb +++ b/spec/truemail/configuration_spec.rb @@ -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 diff --git a/spec/truemail/validator_spec.rb b/spec/truemail/validator_spec.rb index 5d33220..92fb5ff 100644 --- a/spec/truemail/validator_spec.rb +++ b/spec/truemail/validator_spec.rb @@ -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 } diff --git a/spec/truemail_spec.rb b/spec/truemail_spec.rb index 8b8aa68..1ae6add 100644 --- a/spec/truemail_spec.rb +++ b/spec/truemail_spec.rb @@ -133,7 +133,7 @@ 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 @@ -141,19 +141,20 @@ 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 diff --git a/truemail.gemspec b/truemail.gemspec index 0e0a10e..7af326e 100644 --- a/truemail.gemspec +++ b/truemail.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| 'homepage_uri' => 'https://truemail-rb.org', 'changelog_uri' => 'https://github.com/rubygarage/truemail/blob/master/CHANGELOG.md', 'source_code_uri' => 'https://github.com/rubygarage/truemail', - 'documentation_uri' => 'https://truemail-rb.org/truemail-gem/', + 'documentation_uri' => 'https://truemail-rb.org/truemail-gem', 'bug_tracker_uri' => 'https://github.com/rubygarage/truemail/issues' } @@ -43,9 +43,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1' spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.1' spec.add_development_dependency 'rspec', '~> 3.9' - spec.add_development_dependency 'rubocop', '~> 0.89.1' - spec.add_development_dependency 'rubocop-performance', '~> 1.7', '>= 1.7.1' + spec.add_development_dependency 'rubocop', '~> 0.91.0' + spec.add_development_dependency 'rubocop-performance', '~> 1.8', '>= 1.8.1' spec.add_development_dependency 'rubocop-rspec', '~> 1.43', '>= 1.43.2' spec.add_development_dependency 'simplecov', '~> 0.17.1' - spec.add_development_dependency 'truemail-rspec', '~> 0.2.0' + spec.add_development_dependency 'truemail-rspec', '~> 0.2.1' end