Skip to content

Commit

Permalink
Technical/Update gem development dependencies (#77)
Browse files Browse the repository at this point in the history
* Updated gem development dependencies
* Updated reek config
* Changed namespace for rspec helpers
  • Loading branch information
bestwebua authored Oct 17, 2023
1 parent 0ee0be8 commit 7bdde40
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 138 deletions.
10 changes: 5 additions & 5 deletions .circleci/gemspecs/latest
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler-audit', '~> 0.9.1'
spec.add_development_dependency 'fasterer', '~> 0.10.1'
spec.add_development_dependency 'ffaker', '~> 2.21'
spec.add_development_dependency 'net-smtp', '~> 0.3.3'
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.4'
spec.add_development_dependency 'rspec', '~> 3.12'
spec.add_development_dependency 'rubocop', '~> 1.56', '>= 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19'
spec.add_development_dependency 'rubocop-rspec', '~> 2.23', '>= 2.23.2'
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
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
2 changes: 1 addition & 1 deletion smtp_mock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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.3.3' if current_ruby_version >= ::Gem::Version.new('3.1.0')
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
46 changes: 0 additions & 46 deletions spec/support/helpers/client_helper.rb

This file was deleted.

49 changes: 49 additions & 0 deletions spec/support/helpers/context_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module SmtpMock
module RspecHelper
module ContextGenerator
def random_ip_v4_address
ffaker.ip_v4_address
end

def random_hostname
ffaker.domain_name
end

def random_email
ffaker.email
end

def random_pid
random.rand(1_000..2_000)
end

def random_port_number
random.rand(49_152..65_535)
end

def random_signal
random.rand(1..39)
end

def random_message
FFaker::Lorem.sentence
end

def random_sem_version
::Array.new(3) { rand(0..42) }.join('.')
end

private

def ffaker
FFaker::Internet
end

def random
::Random
end
end
end
end
47 changes: 0 additions & 47 deletions spec/support/helpers/context_generator_helper.rb

This file was deleted.

11 changes: 11 additions & 0 deletions spec/support/helpers/dependency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module SmtpMock
module RspecHelper
module Dependency
def compose_command(command_line_args)
SmtpMock::Dependency.compose_command(command_line_args)
end
end
end
end
9 changes: 0 additions & 9 deletions spec/support/helpers/dependency_helper.rb

This file was deleted.

18 changes: 18 additions & 0 deletions spec/support/helpers/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module SmtpMock
module RspecHelper
module Server
def create_fake_servers(active: 1, inactive: 1)
server = ::Struct.new(:active?, :stop!)
active_servers = ::Array.new(active) { server.new(true, true) }
inactive_servers = ::Array.new(inactive) { server.new }
(active_servers + inactive_servers).shuffle
end

def reset_err_log
SmtpMock::Server::Process.instance_variable_set(:@err_log, nil)
end
end
end
end
16 changes: 0 additions & 16 deletions spec/support/helpers/server_helper.rb

This file was deleted.

0 comments on commit 7bdde40

Please sign in to comment.