Skip to content

Commit

Permalink
Technical/Change default Ruby version for test environment (#200)
Browse files Browse the repository at this point in the history
* Changed default Ruby version for test environment
* Updated CircleCI/rubocop/simplecov configs
* Refactored Truemail::Validate::Smtp::Request::Session tests
  • Loading branch information
bestwebua authored Jan 24, 2022
1 parent efa68cd commit eddddec
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
15 changes: 11 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defaults: &defaults
- image: cimg/ruby:<< parameters.ruby-version >>

orbs:
ruby: circleci/ruby@1.2.0
ruby: circleci/ruby@1.4.0

references:
restore_bundle_cache: &restore_bundle_cache
Expand Down Expand Up @@ -40,6 +40,12 @@ references:
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
use_compatible_gemspec: &use_compatible_gemspec
run:
name: Use compatible gemspec
command: |
cp .circleci/gemspec_compatible truemail.gemspec
jobs:
linters-ruby:
parameters:
Expand Down Expand Up @@ -106,6 +112,7 @@ jobs:
- image: cimg/ruby:<< parameters.ruby-version >>
steps:
- checkout
- <<: *use_compatible_gemspec
- ruby/install-deps:
bundler-version: "2.3.5"
with-cache: false
Expand All @@ -121,12 +128,12 @@ workflows:
- linters-ruby:
matrix:
parameters:
ruby-version: ["2.5"]
ruby-version: ["3.1"]
- tests-ruby:
matrix:
parameters:
ruby-version: ["2.5"]
ruby-version: ["3.1"]
- compatibility-ruby:
matrix:
parameters:
ruby-version: ["2.6", "2.7", "3.0", "3.1"]
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
47 changes: 47 additions & 0 deletions .circleci/gemspec_compatible
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'truemail/version'

Gem::Specification.new do |spec|
spec.name = 'truemail'
spec.version = Truemail::VERSION
spec.authors = ['Vladislav Trotsenko']
spec.email = ['[email protected]']

spec.summary = %(truemail)
spec.description = %(Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS, SMTP and even more.)

spec.homepage = 'https://github.com/truemail-rb/truemail'
spec.license = 'MIT'

spec.metadata = {
'homepage_uri' => 'https://truemail-rb.org',
'changelog_uri' => 'https://github.com/truemail-rb/truemail/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/truemail-rb/truemail',
'documentation_uri' => 'https://truemail-rb.org/truemail-gem',
'bug_tracker_uri' => 'https://github.com/truemail-rb/truemail/issues'
}

spec.required_ruby_version = '>= 2.5.0'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| ::File.basename(f) }
spec.require_paths = ['lib']

spec.add_runtime_dependency 'net-smtp', '~> 0.3' if ::RUBY_VERSION >= '3.1.0'
spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'dns_mock', '~> 1.5'
spec.add_development_dependency 'ffaker', '~> 2.20'
spec.add_development_dependency 'json_matchers', '~> 0.11.1'
spec.add_development_dependency 'pry-byebug', '~> 3.9'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'rspec', '~> 3.10'
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
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,6 @@ RSpec/SubjectDeclaration:

RSpec/FactoryBot/SyntaxMethods:
Enabled: true

RSpec/SubjectStub:
Enabled: false
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.5.0
ruby-3.1.0
2 changes: 1 addition & 1 deletion spec/support/config/simplecov.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

if ::RUBY_VERSION[/\A2\.5.+\z/]
if ::RUBY_VERSION[/\A3\.1.+\z/]
require 'simplecov'

SimpleCov.minimum_coverage(100)
Expand Down
15 changes: 4 additions & 11 deletions spec/truemail/validate/smtp/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@
RSpec.describe Truemail::Validate::Smtp::Request::Session do
subject(:request_session_instance) { described_class.new(host, port, connection_timeout, response_timeout) }

let(:const_state) { ::Net::SMTP::VERSION if ::Net::SMTP.const_defined?(:VERSION) }

let(:host) { random_domain_name }
let(:port) { 42 }
let(:connection_timeout) { 13 }
Expand All @@ -329,12 +327,9 @@
describe '.new' do
subject(:request_net_smtp_instance) { request_session_instance.send(:net_smtp) }

context 'when out of the box Net::SMTP version' do
before { ::Net::SMTP.send(:remove_const, :VERSION) if ::Net::SMTP.const_defined?(:VERSION) }

after { ::Net::SMTP.send(:const_set, :VERSION, const_state) if const_state }

context 'when undefined Net::SMTP version' do
it 'creates session instance with net smtp instance inside' do
expect(::Net::SMTP).to receive(:const_defined?).with(:VERSION).and_return(false)
expect(::Net::SMTP).to receive(:new).with(host, port).and_return(net_smtp_instance)
expect(request_net_smtp_instance.open_timeout).to eq(connection_timeout)
expect(request_net_smtp_instance.read_timeout).to eq(response_timeout)
Expand Down Expand Up @@ -366,14 +361,12 @@
let(:helo_domain) { random_domain_name }
let(:session_actions) { proc {} }

context 'when out of the box Net::SMTP version' do
context 'when undefined Net::SMTP version' do
before do
::Net::SMTP.send(:remove_const, :VERSION) if ::Net::SMTP.const_defined?(:VERSION)
allow(::Net::SMTP).to receive(:const_defined?).with(:VERSION).and_return(false)
allow(::Net::SMTP).to receive(:new).with(host, port).and_return(net_smtp_instance)
end

after { ::Net::SMTP.send(:const_set, :VERSION, const_state) if const_state }

it 'passes helo domain as position argument' do
expect(net_smtp_instance).to receive(:start).with(helo_domain, &session_actions)
session_start
Expand Down

0 comments on commit eddddec

Please sign in to comment.