smtp_mock 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6fcd84a6232032428e31f2d0627b9c72a98a74a257dcb7638fb8b0bb11dbba5
4
- data.tar.gz: 1b06de5c2a1009eb9dddc7f3b1aa2a15573f6f2ff2fadd2a4d81fb50c8c7d91f
3
+ metadata.gz: 6e7b1afecc17c4c1905acc7008dece2c87908a622adf0d3e7fa4093b3385584d
4
+ data.tar.gz: a8e006258b42098c2b35cbadd10b7004b7099942d18cdd6baec533fc7abc62c7
5
5
  SHA512:
6
- metadata.gz: bd6df23a441cebf9a7d597d770f16af4548880da884082c32e91f507399a76e953a274ee6985f963143cd5fac98560cd5d9563896c3f8019a26ee266f4c29d3a
7
- data.tar.gz: aa7c24286f3e74b059b48f3d59f67e5dd4548feabcdc3cd85ae6381d8950c64ec5042ca84baa6d06e1a55155668f2f296c7e6fd95bf1bcdb6614e81024ea282c
6
+ metadata.gz: 9713d4cd810845321ce7b7bce79717382da3652b3475836342e5a68433d7ee92246ff456285cc905d862030801a7c545b89780100bd5e867ab433f6bf82ae29a
7
+ data.tar.gz: cd51a1f5a1bd7f70b9babe5b4cf2cbfd8ab17333bd1b739a941f598960b1b6e1de8baddceda89aad0e0276ddf64a1ba17074fed4989a2d09e62b0aa0638ccb0f
data/.circleci/config.yml CHANGED
@@ -6,7 +6,7 @@ defaults: &defaults
6
6
  - image: cimg/ruby:<< parameters.ruby-version >>
7
7
 
8
8
  orbs:
9
- ruby: circleci/ruby@1.2.0
9
+ ruby: circleci/ruby@1.4.0
10
10
 
11
11
  references:
12
12
  restore_bundle_cache: &restore_bundle_cache
@@ -40,6 +40,12 @@ references:
40
40
  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
41
41
  chmod +x ./cc-test-reporter
42
42
 
43
+ use_compatible_gemspec: &use_compatible_gemspec
44
+ run:
45
+ name: Use compatible gemspec
46
+ command: |
47
+ cp .circleci/gemspec_compatible smtp_mock.gemspec
48
+
43
49
  jobs:
44
50
  linters-ruby:
45
51
  parameters:
@@ -106,6 +112,7 @@ jobs:
106
112
  - image: cimg/ruby:<< parameters.ruby-version >>
107
113
  steps:
108
114
  - checkout
115
+ - <<: *use_compatible_gemspec
109
116
  - ruby/install-deps:
110
117
  bundler-version: "2.3.5"
111
118
  with-cache: false
@@ -121,12 +128,12 @@ workflows:
121
128
  - linters-ruby:
122
129
  matrix:
123
130
  parameters:
124
- ruby-version: ["2.5"]
131
+ ruby-version: ["3.1"]
125
132
  - tests-ruby:
126
133
  matrix:
127
134
  parameters:
128
- ruby-version: ["2.5"]
135
+ ruby-version: ["3.1"]
129
136
  - compatibility-ruby:
130
137
  matrix:
131
138
  parameters:
132
- ruby-version: ["2.6", "2.7", "3.0", "3.1"]
139
+ ruby-version: ["2.5", "2.6", "2.7", "3.0"]
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = ::File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'smtp_mock/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'smtp_mock'
9
+ spec.version = SmtpMock::VERSION
10
+ spec.authors = ['Vladislav Trotsenko']
11
+ spec.email = ['admin@bestweb.com.ua']
12
+
13
+ spec.summary = %(smtp_mock)
14
+ spec.description = %(💎 Ruby SMTP mock. Mimic any SMTP server behaviour for your test environment.)
15
+
16
+ spec.homepage = 'https://github.com/mocktools/ruby-smtp-mock'
17
+ spec.license = 'MIT'
18
+
19
+ spec.metadata = {
20
+ 'homepage_uri' => 'https://github.com/mocktools/ruby-smtp-mock',
21
+ 'changelog_uri' => 'https://github.com/mocktools/ruby-smtp-mock/blob/master/CHANGELOG.md',
22
+ 'source_code_uri' => 'https://github.com/mocktools/ruby-smtp-mock',
23
+ 'documentation_uri' => 'https://github.com/mocktools/ruby-smtp-mock/blob/master/README.md',
24
+ 'bug_tracker_uri' => 'https://github.com/mocktools/ruby-smtp-mock/issues'
25
+ }
26
+
27
+ spec.required_ruby_version = '>= 2.5.0'
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ spec.executables = %w[smtp_mock]
31
+ spec.require_paths = %w[lib]
32
+
33
+ spec.add_runtime_dependency 'dry-struct', '~> 1.4'
34
+
35
+ spec.add_development_dependency 'ffaker', '~> 2.20'
36
+ spec.add_development_dependency 'pry-byebug', '~> 3.9'
37
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
38
+ spec.add_development_dependency 'rspec', '~> 3.10'
39
+ end
data/.codeclimate.yml CHANGED
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-24
10
+ channel: rubocop-1-25
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -9,6 +9,7 @@ detectors:
9
9
  - SmtpMock::ServerHelper
10
10
  - SmtpMock::TestFramework::RSpec::Helper#smtp_mock_server
11
11
  - SmtpMock::ContextGeneratorHelper#random_message
12
+ - SmtpMock::Cli::Resolver#install_to
12
13
 
13
14
  NestedIterators:
14
15
  exclude:
data/.rubocop.yml CHANGED
@@ -290,9 +290,6 @@ Gemspec/DateAssignment:
290
290
  Gemspec/RequireMFA:
291
291
  Enabled: false
292
292
 
293
- Gemspec/RubyVersionGlobalsUsage:
294
- Enabled: false
295
-
296
293
  Security/IoMethods:
297
294
  Enabled: true
298
295
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.5.0
1
+ ruby-3.1.0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  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).
4
4
 
5
+ ## [1.0.0] - 2022-01-31
6
+
7
+ ### Added
8
+
9
+ - Added `smtpmock` version checker
10
+ - Added command for upgrade `smtpmock` to latest version
11
+ - Added `SmtpMock::Error::Dependency::SMTPMOCK_MIN_VERSION`
12
+ - Added `SmtpMock::Server#version`, tests
13
+
14
+ ### Updated
15
+
16
+ - Updated `SmtpMock::Dependency.verify_dependencies`, tests
17
+ - Updated `SmtpMock::Cli::Command`, tests
18
+ - Updated gem version, documentation
19
+
5
20
  ## [0.1.2] - 2022-01-24
6
21
 
7
22
  ### Updated
data/README.md CHANGED
@@ -77,8 +77,9 @@ This gem includes easy system dependency manager. Run `bundle exec smtp_mock` wi
77
77
  | Flag | Description | Example of usage |
78
78
  | --- | --- | --- |
79
79
  | `-s`, `--sudo` | Run command as sudo | `bundle exec smtp_mock -s -i ~` |
80
- | `-i`, `--install=PATH` | Install smtpmock to the existing path | `bundle exec smtp_mock -i ~/existent_dir` |
81
- | `-u`, `--uninstall` | Uninstall smtpmock | `bundle exec smtp_mock -u` |
80
+ | `-i`, `--install=PATH` | Install `smtpmock` to the existing path | `bundle exec smtp_mock -i ~/existent_dir` |
81
+ | `-u`, `--uninstall` | Uninstall `smtpmock` | `bundle exec smtp_mock -u` |
82
+ | `-g`, `--upgrade` | Upgrade to latest version of `smtpmock` | `bundle exec smtp_mock -g` |
82
83
  | `-h`, `--help` | Prints help | `bundle exec smtp_mock -h` |
83
84
 
84
85
  ### DSL
@@ -134,6 +135,9 @@ smtp_mock_server.port # => 55640
134
135
  # returns current smtp mock server port
135
136
  smtp_mock_server.pid # => 38195
136
137
 
138
+ # returns current smtp mock server version
139
+ smtp_mock_server.version # => '1.5.2'
140
+
137
141
  # interface for graceful shutdown current smtp mock server
138
142
  smtp_mock_server.stop # => true
139
143
 
@@ -12,34 +12,34 @@ module SmtpMock
12
12
  opt_parser = ::OptionParser.new do |parser|
13
13
  parser.banner = SmtpMock::Cli::Resolver::USE_CASE
14
14
 
15
- parser.on('-s', '--sudo', 'Run command as sudo') do
16
- self.sudo = true
17
- end
15
+ parser.on('-s', '--sudo', 'Run command as sudo') { self.sudo = true }
18
16
 
19
17
  parser.on('-iPATH', '--install=PATH', 'Install smtpmock to the existing path') do |argument|
20
18
  self.install_path = argument
21
19
  return self.message = 'smtpmock is already installed' if ::File.exist?(binary_path)
22
20
 
23
- ::Kernel.system("cd #{install_path} && curl -sL #{SmtpMock::Cli::Resolver::DOWNLOAD_SCRIPT} | bash")
21
+ install_to(install_path)
24
22
  ::Kernel.system("#{as_sudo}ln -s #{binary_path} #{SmtpMock::Dependency::SYMLINK}")
25
-
26
23
  self.message = 'smtpmock was installed successfully'
27
24
  end
28
25
 
29
26
  parser.on('-u', '--uninstall', 'Uninstall smtpmock') do
30
- current_smtpmock_path = SmtpMock::Dependency.smtpmock_path_by_symlink
31
- return self.message = 'smtpmock not installed yet' if current_smtpmock_path.empty?
27
+ return if not_installed? # rubocop:disable Lint/NonLocalExitFromIterator
32
28
 
33
29
  ::Kernel.system("#{as_sudo}unlink #{SmtpMock::Dependency::SYMLINK}")
34
30
  ::Kernel.system("rm #{current_smtpmock_path}")
35
-
36
31
  self.message = 'smtpmock was uninstalled successfully'
37
32
  end
38
33
 
39
- parser.on('-h', '--help', 'Prints help') do
40
- self.message = parser.to_s
34
+ parser.on('-g', '--upgrade', 'Upgrade to latest version of smtpmock') do
35
+ return if not_installed? # rubocop:disable Lint/NonLocalExitFromIterator
36
+
37
+ install_to(current_smtpmock_path[%r{(.+)/.+}, 1])
38
+ self.message = 'smtpmock was upgraded successfully'
41
39
  end
42
40
 
41
+ parser.on('-h', '--help', 'Prints help') { self.message = parser.to_s }
42
+
43
43
  self.success = true
44
44
  end
45
45
 
@@ -52,9 +52,23 @@ module SmtpMock
52
52
  "#{install_path}/smtpmock"
53
53
  end
54
54
 
55
+ def install_to(install_path)
56
+ ::Kernel.system("cd #{install_path} && curl -sL #{SmtpMock::Cli::Resolver::DOWNLOAD_SCRIPT} | bash")
57
+ end
58
+
55
59
  def as_sudo
56
60
  return 'sudo ' if sudo
57
61
  end
62
+
63
+ def current_smtpmock_path
64
+ @current_smtpmock_path ||= SmtpMock::Dependency.smtpmock_path_by_symlink
65
+ end
66
+
67
+ def not_installed?
68
+ return false unless current_smtpmock_path.empty?
69
+ self.message = 'smtpmock not installed yet'
70
+ true
71
+ end
58
72
  end
59
73
  end
60
74
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmtpMock
4
+ SMTPMOCK_MIN_VERSION = '1.5.0'
5
+
4
6
  module Error
5
7
  require_relative '../smtp_mock/error/argument'
6
8
  require_relative '../smtp_mock/error/dependency'
@@ -4,6 +4,7 @@ module SmtpMock
4
4
  module Dependency
5
5
  BINARY_SHORTCUT = 'smtpmock'
6
6
  SYMLINK = "/usr/local/bin/#{BINARY_SHORTCUT}"
7
+ VERSION_REGEX_PATTERN = /#{BINARY_SHORTCUT}: (.+)/.freeze
7
8
 
8
9
  class << self
9
10
  def smtpmock_path_by_symlink
@@ -16,11 +17,27 @@ module SmtpMock
16
17
 
17
18
  def verify_dependencies
18
19
  raise SmtpMock::Error::Dependency, SmtpMock::Error::Dependency::SMTPMOCK_NOT_INSTALLED unless smtpmock?
20
+ current_version = version
21
+ raise SmtpMock::Error::Dependency, SmtpMock::Error::Dependency::SMTPMOCK_MIN_VERSION unless minimal_version?(current_version)
22
+ current_version
19
23
  end
20
24
 
21
25
  def compose_command(command_line_args)
22
26
  "#{SmtpMock::Dependency::BINARY_SHORTCUT} #{command_line_args}".strip
23
27
  end
28
+
29
+ private
30
+
31
+ def version
32
+ ::Kernel.public_send(
33
+ :`,
34
+ "#{SmtpMock::Dependency::BINARY_SHORTCUT} -v"
35
+ )[SmtpMock::Dependency::VERSION_REGEX_PATTERN, 1]
36
+ end
37
+
38
+ def minimal_version?(current_version)
39
+ !!current_version && current_version >= SmtpMock::SMTPMOCK_MIN_VERSION
40
+ end
24
41
  end
25
42
  end
26
43
  end
@@ -4,6 +4,7 @@ module SmtpMock
4
4
  module Error
5
5
  class Dependency < ::RuntimeError
6
6
  SMTPMOCK_NOT_INSTALLED = 'smtpmock is required system dependency. Run `bundle exec smtp_mock -h` for details'
7
+ SMTPMOCK_MIN_VERSION = "smtpmock #{SmtpMock::SMTPMOCK_MIN_VERSION} or higher is required. Run `bundle exec smtp_mock -g` for version upgrade"
7
8
  end
8
9
  end
9
10
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SmtpMock
4
4
  class Server
5
- attr_reader :pid, :port
5
+ attr_reader :pid, :port, :version
6
6
 
7
7
  def initialize( # rubocop:disable Metrics/ParameterLists
8
8
  deps_handler = SmtpMock::Dependency,
@@ -11,7 +11,7 @@ module SmtpMock
11
11
  process = SmtpMock::Server::Process,
12
12
  **args
13
13
  )
14
- deps_handler.verify_dependencies
14
+ @version = deps_handler.verify_dependencies
15
15
  args[:port] = port_checker.random_free_port unless args.include?(:port)
16
16
  @command_line_args, @port = args_builder.call(**args), args[:port]
17
17
  @deps_handler, @port_checker, @process = deps_handler, port_checker, process
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmtpMock
4
- VERSION = '0.1.2'
4
+ VERSION = '1.0.0'
5
5
  end
data/smtp_mock.gemspec CHANGED
@@ -36,14 +36,14 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'bundler-audit', '~> 0.9.0.1'
37
37
  spec.add_development_dependency 'fasterer', '~> 0.9.0'
38
38
  spec.add_development_dependency 'ffaker', '~> 2.20'
39
- spec.add_development_dependency 'net-smtp', '~> 0.3' if ::RUBY_VERSION >= '3.1.0'
39
+ spec.add_development_dependency 'net-smtp', '~> 0.3.1'
40
40
  spec.add_development_dependency 'overcommit', '~> 0.58.0'
41
41
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
42
42
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
43
- spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.6'
43
+ spec.add_development_dependency 'reek', '~> 6.1'
44
44
  spec.add_development_dependency 'rspec', '~> 3.10'
45
- spec.add_development_dependency 'rubocop', '~> 1.24'
46
- spec.add_development_dependency 'rubocop-performance', '~> 1.13'
47
- spec.add_development_dependency 'rubocop-rspec', '~> 2.7'
48
- spec.add_development_dependency 'simplecov', '~> 0.17.1'
45
+ spec.add_development_dependency 'rubocop', '~> 1.25'
46
+ spec.add_development_dependency 'rubocop-performance', '~> 1.13', '>= 1.13.2'
47
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.8'
48
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
49
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smtp_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-24 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.20'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-smtp
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.1
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: overcommit
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -120,20 +134,14 @@ dependencies:
120
134
  requirements:
121
135
  - - "~>"
122
136
  - !ruby/object:Gem::Version
123
- version: '6.0'
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: 6.0.6
137
+ version: '6.1'
127
138
  type: :development
128
139
  prerelease: false
129
140
  version_requirements: !ruby/object:Gem::Requirement
130
141
  requirements:
131
142
  - - "~>"
132
143
  - !ruby/object:Gem::Version
133
- version: '6.0'
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- version: 6.0.6
144
+ version: '6.1'
137
145
  - !ruby/object:Gem::Dependency
138
146
  name: rspec
139
147
  requirement: !ruby/object:Gem::Requirement
@@ -154,14 +162,14 @@ dependencies:
154
162
  requirements:
155
163
  - - "~>"
156
164
  - !ruby/object:Gem::Version
157
- version: '1.24'
165
+ version: '1.25'
158
166
  type: :development
159
167
  prerelease: false
160
168
  version_requirements: !ruby/object:Gem::Requirement
161
169
  requirements:
162
170
  - - "~>"
163
171
  - !ruby/object:Gem::Version
164
- version: '1.24'
172
+ version: '1.25'
165
173
  - !ruby/object:Gem::Dependency
166
174
  name: rubocop-performance
167
175
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +177,9 @@ dependencies:
169
177
  - - "~>"
170
178
  - !ruby/object:Gem::Version
171
179
  version: '1.13'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 1.13.2
172
183
  type: :development
173
184
  prerelease: false
174
185
  version_requirements: !ruby/object:Gem::Requirement
@@ -176,34 +187,37 @@ dependencies:
176
187
  - - "~>"
177
188
  - !ruby/object:Gem::Version
178
189
  version: '1.13'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 1.13.2
179
193
  - !ruby/object:Gem::Dependency
180
194
  name: rubocop-rspec
181
195
  requirement: !ruby/object:Gem::Requirement
182
196
  requirements:
183
197
  - - "~>"
184
198
  - !ruby/object:Gem::Version
185
- version: '2.7'
199
+ version: '2.8'
186
200
  type: :development
187
201
  prerelease: false
188
202
  version_requirements: !ruby/object:Gem::Requirement
189
203
  requirements:
190
204
  - - "~>"
191
205
  - !ruby/object:Gem::Version
192
- version: '2.7'
206
+ version: '2.8'
193
207
  - !ruby/object:Gem::Dependency
194
208
  name: simplecov
195
209
  requirement: !ruby/object:Gem::Requirement
196
210
  requirements:
197
211
  - - "~>"
198
212
  - !ruby/object:Gem::Version
199
- version: 0.17.1
213
+ version: 0.21.2
200
214
  type: :development
201
215
  prerelease: false
202
216
  version_requirements: !ruby/object:Gem::Requirement
203
217
  requirements:
204
218
  - - "~>"
205
219
  - !ruby/object:Gem::Version
206
- version: 0.17.1
220
+ version: 0.21.2
207
221
  description: "\U0001F48E Ruby SMTP mock. Mimic any SMTP server behaviour for your
208
222
  test environment."
209
223
  email:
@@ -214,6 +228,7 @@ extensions: []
214
228
  extra_rdoc_files: []
215
229
  files:
216
230
  - ".circleci/config.yml"
231
+ - ".circleci/gemspec_compatible"
217
232
  - ".codeclimate.yml"
218
233
  - ".github/BRANCH_NAMING_CONVENTION.md"
219
234
  - ".github/ISSUE_TEMPLATE/bug_report.md"
@@ -281,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
296
  - !ruby/object:Gem::Version
282
297
  version: '0'
283
298
  requirements: []
284
- rubygems_version: 3.2.20
299
+ rubygems_version: 3.3.3
285
300
  signing_key:
286
301
  specification_version: 4
287
302
  summary: smtp_mock