Skip to content

Commit

Permalink
Merge pull request #79 from mocktools/develop
Browse files Browse the repository at this point in the history
Ruby SmtpMock v1.3.5
  • Loading branch information
bestwebua committed Oct 17, 2023
2 parents 8aa82ea + bd02b05 commit 6306cb9
Show file tree
Hide file tree
Showing 26 changed files with 203 additions and 171 deletions.
56 changes: 32 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,20 @@ defaults: &defaults
- image: cimg/ruby:<< parameters.ruby-version >>

orbs:
ruby: circleci/ruby@2.0.0
ruby: circleci/ruby@2.1.0

references:
restore_bundle_cache: &restore_bundle_cache
restore_cache:
keys:
- ruby-smtp-mock-{{ checksum "smtp_mock.gemspec" }}
paths:
- ~/vendor/bundle

bundle_install: &bundle_install
run:
name: Installing gems
command: |
bundle config set --local path '~/vendor/bundle'
bundle install
save_bundle_cache: &save_bundle_cache
save_cache:
key: ruby-smtp-mock-{{ checksum "smtp_mock.gemspec" }}
paths:
- ~/vendor/bundle

system_dependencies: &system_dependencies
install_system_dependencies: &install_system_dependencies
run:
name: Installing system requirements
command: |
bundle exec smtp_mock -s -i ~
name: Installing system dependencies
command: bundle exec smtp_mock -s -i ~

install_linters: &install_linters
run:
Expand All @@ -55,6 +41,11 @@ references:
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
use_latest_bundler: &use_latest_bundler
run:
name: Using latest bundler
command: gem install bundler

use_latest_gemspec: &use_latest_gemspec
run:
name: Using latest gemspec
Expand All @@ -76,10 +67,9 @@ jobs:
steps:
- checkout

- <<: *use_latest_bundler
- <<: *use_latest_gemspec
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
- <<: *install_linters

- run:
Expand Down Expand Up @@ -112,11 +102,10 @@ jobs:
steps:
- checkout

- <<: *use_latest_bundler
- <<: *use_latest_gemspec
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
- <<: *system_dependencies
- <<: *install_system_dependencies
- <<: *install_codeclimate_reporter

- run:
Expand Down Expand Up @@ -157,12 +146,26 @@ jobs:
with-cache: false
path: '~/vendor/custom_bundle'

- <<: *system_dependencies
- <<: *install_system_dependencies

- run:
name: Running compatibility tests
command: bundle exec rspec

rubygems-deps-ruby:
parameters:
ruby-version:
type: string

<<: *defaults

steps:
- checkout

- run:
name: Building rubygems dependencies from default gemspec on minimal Ruby version
command: bundle install

releasing-gem-from-ruby:
parameters:
ruby-version:
Expand Down Expand Up @@ -196,11 +199,16 @@ workflows:
matrix:
parameters:
ruby-version: ["2.5", "2.6", "2.7", "3.0", "3.1"]
- rubygems-deps-ruby:
matrix:
parameters:
ruby-version: ["2.5"]
- releasing-gem-from-ruby:
requires:
- linters-ruby
- tests-ruby
- compatibility-ruby
- rubygems-deps-ruby
matrix:
parameters:
ruby-version: ["2.5"]
Expand Down
14 changes: 7 additions & 7 deletions .circleci/gemspecs/latest
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'dry-struct', '~> 1.6'

spec.add_development_dependency 'bundler-audit', '~> 0.9.1'
spec.add_development_dependency 'fasterer', '~> 0.10.0'
spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'net-smtp', '~> 0.3.3'
spec.add_development_dependency 'fasterer', '~> 0.10.1'
spec.add_development_dependency 'ffaker', '~> 2.23'
spec.add_development_dependency 'net-smtp', '~> 0.4.0'
spec.add_development_dependency 'pry-byebug', '~> 3.10', '>= 3.10.1'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.3'
spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.4'
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'rubocop', '~> 1.42'
spec.add_development_dependency 'rubocop-performance', '~> 1.15', '>= 1.15.2'
spec.add_development_dependency 'rubocop-rspec', '~> 2.16'
spec.add_development_dependency 'rubocop', '~> 1.57', '>= 1.57.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19', '>= 1.19.1'
spec.add_development_dependency 'rubocop-rspec', '~> 2.24', '>= 2.24.1'
spec.add_development_dependency 'simplecov', '~> 0.22.0'
end
3 changes: 3 additions & 0 deletions .circleci/linter_configs/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Layout/EmptyLineAfterGuardClause:
Gemspec/RequireMFA:
Enabled: false

Gemspec/DevelopmentDependencies:
Enabled: false

# Performance -----------------------------------------------------------------

Performance/MethodObjectAsBlock:
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-42
channel: rubocop-1-56
config:
file: .circleci/linter_configs/.rubocop.yml

Expand Down
12 changes: 7 additions & 5 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ detectors:
UtilityFunction:
exclude:
- SmtpMock::CommandLineArgsBuilder#to_camel_case
- SmtpMock::DependencyHelper#compose_command
- SmtpMock::Cli::Resolver#install_to
- SmtpMock::ServerHelper
- SmtpMock::TestFramework::RSpec::Helper#smtp_mock_server
- SmtpMock::ContextGeneratorHelper#random_message
- SmtpMock::Cli::Resolver#install_to
- SmtpMock::RspecHelper::ContextGenerator#random_message
- SmtpMock::RspecHelper::Dependency#compose_command
- SmtpMock::RspecHelper::Server#create_fake_servers
- SmtpMock::RspecHelper::Server#reset_err_log

NestedIterators:
exclude:
Expand All @@ -20,14 +22,14 @@ detectors:
TooManyStatements:
exclude:
- SmtpMock::Server#run
- SmtpMock::ServerHelper#create_fake_servers
- SmtpMock::Cli::Resolver#install
- SmtpMock::Cli::Resolver#resolve
- SmtpMock::RspecHelper::Server#create_fake_servers

TooManyInstanceVariables:
exclude:
- SmtpMock::Server

LongParameterList:
exclude:
- SmtpMock::ClientHelper#smtp_request
- SmtpMock::RspecHelper::Client#smtp_request
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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.3.5] - 2023-10-17

### Updated

- Updated gem development dependencies
- Updated RSpec structure
- Updated linters configs
- Updated gem version

## [1.3.4] - 2023-01-11

### Updated
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
reported by contacting the project team at <[email protected]>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
2 changes: 1 addition & 1 deletion lib/smtp_mock/cli/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def install_to(install_path)
end

def as_sudo
return 'sudo ' if sudo
'sudo ' if sudo
end

def current_smtpmock_path
Expand Down
4 changes: 2 additions & 2 deletions lib/smtp_mock/test_framework/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require 'rspec/core'
require_relative '../../smtp_mock'
require_relative './rspec/interface'
require_relative './rspec/helper'
require_relative 'rspec/interface'
require_relative 'rspec/helper'

RSpec.configure do |config|
config.after { SmtpMock::TestFramework::RSpec::Interface.stop_server! }
Expand Down
2 changes: 1 addition & 1 deletion lib/smtp_mock/test_framework/rspec/helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative './interface'
require_relative 'interface'

module SmtpMock
module TestFramework
Expand Down
2 changes: 1 addition & 1 deletion lib/smtp_mock/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SmtpMock
VERSION = '1.3.4'
VERSION = '1.3.5'
end
4 changes: 3 additions & 1 deletion smtp_mock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
'bug_tracker_uri' => 'https://github.com/mocktools/ruby-smtp-mock/issues'
}

dry_struct_version = ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new('2.7.0') ? '~> 1.6' : '~> 1.4'
current_ruby_version = ::Gem::Version.new(::RUBY_VERSION)
dry_struct_version = current_ruby_version >= ::Gem::Version.new('2.7.0') ? '~> 1.6' : '~> 1.4'

spec.required_ruby_version = '>= 2.5.0'
spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r{^(bin|lib|tmp)/|.ruby-version|smtp_mock.gemspec|LICENSE}) }
Expand All @@ -33,6 +34,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'dry-struct', dry_struct_version

spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'net-smtp', '~> 0.4.0' if current_ruby_version >= ::Gem::Version.new('3.1.0')
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'rspec', '~> 3.12'
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe SmtpMock::ClientHelper::SmtpClient, type: :helper do # rubocop:disable RSpec/FilePath
RSpec.describe SmtpMock::RspecHelper::Client::SmtpClient, type: :helper do
subject(:smtp_client_instance) { described_class.new(host, port, net_class) }

let(:host) { random_hostname }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe SmtpMock::ContextGeneratorHelper, type: :helper do # rubocop:disable RSpec/FilePath
RSpec.describe SmtpMock::RspecHelper::ContextGenerator, type: :helper do
describe '#random_ip_v4_address' do
it 'returns random ip v4 address' do
expect(FFaker::Internet).to receive(:ip_v4_address).and_call_original
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe SmtpMock::DependencyHelper, type: :helper do # rubocop:disable RSpec/FilePath
RSpec.describe SmtpMock::RspecHelper::Dependency, type: :helper do
describe '#compose_command' do
let(:command_line_args) { '-a -b 42' }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe SmtpMock::ServerHelper, type: :helper do # rubocop:disable RSpec/FilePath
RSpec.describe SmtpMock::RspecHelper::Server, type: :helper do
describe '#create_fake_servers' do
subject(:fake_servers) { create_fake_servers(**options) }

Expand Down
2 changes: 1 addition & 1 deletion spec/smtp_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
rcptto: rcptto,
message: random_message
)
end.to raise_error(SmtpMock::ClientHelper::SmtpClient::Error, expected_response_message)
end.to raise_error(SmtpMock::RspecHelper::Client::SmtpClient::Error, expected_response_message)

smtp_mock_server.stop!
end
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
config.disable_monkey_patching!
config.order = :random

config.include SmtpMock::ContextGeneratorHelper
config.include SmtpMock::DependencyHelper
config.include SmtpMock::ServerHelper
config.include SmtpMock::ClientHelper
config.include SmtpMock::RspecHelper::ContextGenerator
config.include SmtpMock::RspecHelper::Dependency
config.include SmtpMock::RspecHelper::Server
config.include SmtpMock::RspecHelper::Client

::Kernel.srand(config.seed)
end
48 changes: 48 additions & 0 deletions spec/support/helpers/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

module SmtpMock
module RspecHelper
module Client
class SmtpClient
require 'net/smtp'

UNDEFINED_VERSION = '0.0.0'

Error = ::Class.new(::StandardError)

def initialize(host, port, net_class = ::Net::SMTP)
@net_class = net_class
@net_smtp_version = resolve_net_smtp_version
@net_smtp = old_net_smtp? ? net_class.new(host, port) : net_class.new(host, port, tls_verify: false)
end

def start(helo_domain, &block)
return net_smtp.start(helo_domain, &block) if net_smtp_version < '0.2.0'
return net_smtp.start(helo_domain, tls_verify: false, &block) if old_net_smtp?
net_smtp.start(helo: helo_domain, &block)
end

private

attr_reader :net_class, :net_smtp_version, :net_smtp

def resolve_net_smtp_version
return net_class::VERSION if net_class.const_defined?(:VERSION)
SmtpMock::RspecHelper::Client::SmtpClient::UNDEFINED_VERSION
end

def old_net_smtp?
net_smtp_version < '0.3.0'
end
end

def smtp_request(host:, port:, mailfrom:, rcptto:, message:, helo_domain: nil) # rubocop:disable Metrics/ParameterLists
SmtpMock::RspecHelper::Client::SmtpClient.new(host, port).start(helo_domain) do |session|
session.send_message(message, mailfrom, rcptto)
rescue ::Net::SMTPFatalError => error
raise SmtpMock::RspecHelper::Client::SmtpClient::Error, error.message.strip
end
end
end
end
end
Loading

0 comments on commit 6306cb9

Please sign in to comment.