elapsed 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -8,146 +8,58 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (7.2.0)
12
- actionview (= 7.2.0)
13
- activesupport (= 7.2.0)
14
- nokogiri (>= 1.8.5)
15
- racc
16
- rack (>= 2.2.4, < 3.2)
17
- rack-session (>= 1.0.1)
18
- rack-test (>= 0.6.3)
19
- rails-dom-testing (~> 2.2)
20
- rails-html-sanitizer (~> 1.6)
21
- useragent (~> 0.16)
22
- actionview (7.2.0)
23
- activesupport (= 7.2.0)
24
- builder (~> 3.1)
25
- erubi (~> 1.11)
26
- rails-dom-testing (~> 2.2)
27
- rails-html-sanitizer (~> 1.6)
28
- activesupport (7.2.0)
29
- base64
30
- bigdecimal
31
- concurrent-ruby (~> 1.0, >= 1.3.1)
32
- connection_pool (>= 2.2.5)
33
- drb
34
- i18n (>= 1.6, < 2)
35
- logger (>= 1.4.2)
36
- minitest (>= 5.1)
37
- securerandom (>= 0.3)
38
- tzinfo (~> 2.0, >= 2.0.5)
39
- ast (2.4.2)
40
- base64 (0.2.0)
41
- bigdecimal (3.1.8)
11
+ ansi (1.5.0)
12
+ ast (2.4.3)
42
13
  builder (3.3.0)
43
- concurrent-ruby (1.3.4)
44
- connection_pool (2.4.1)
45
- crass (1.0.6)
46
- diff-lcs (1.5.1)
47
14
  docile (1.4.1)
48
- drb (2.2.1)
49
- erubi (1.13.0)
50
- i18n (1.14.5)
51
- concurrent-ruby (~> 1.0)
52
- io-console (0.7.2)
53
- irb (1.14.0)
54
- rdoc (>= 4.0.0)
55
- reline (>= 0.4.2)
56
- json (2.7.2)
57
- language_server-protocol (3.17.0.3)
58
- logger (1.6.0)
59
- loofah (2.22.0)
60
- crass (~> 1.0.2)
61
- nokogiri (>= 1.12.0)
62
- loog (0.6.0)
63
- minitest (5.25.0)
64
- nokogiri (1.16.7-aarch64-linux)
65
- racc (~> 1.4)
66
- nokogiri (1.16.7-arm-linux)
67
- racc (~> 1.4)
68
- nokogiri (1.16.7-arm64-darwin)
69
- racc (~> 1.4)
70
- nokogiri (1.16.7-x64-mingw-ucrt)
71
- racc (~> 1.4)
72
- nokogiri (1.16.7-x86-linux)
73
- racc (~> 1.4)
74
- nokogiri (1.16.7-x86_64-darwin)
75
- racc (~> 1.4)
76
- nokogiri (1.16.7-x86_64-linux)
77
- racc (~> 1.4)
78
- parallel (1.26.2)
79
- parser (3.3.4.2)
15
+ json (2.12.2)
16
+ language_server-protocol (3.17.0.5)
17
+ lint_roller (1.1.0)
18
+ logger (1.7.0)
19
+ loog (0.6.1)
20
+ logger (~> 1.0)
21
+ minitest (5.25.5)
22
+ minitest-reporters (1.7.1)
23
+ ansi
24
+ builder
25
+ minitest (>= 5.0)
26
+ ruby-progressbar
27
+ parallel (1.27.0)
28
+ parser (3.3.8.0)
80
29
  ast (~> 2.4.1)
81
30
  racc
82
- psych (5.1.2)
83
- stringio
31
+ prism (1.4.0)
84
32
  racc (1.8.1)
85
- rack (3.1.7)
86
- rack-session (2.0.0)
87
- rack (>= 3.0.0)
88
- rack-test (2.1.0)
89
- rack (>= 1.3)
90
- rackup (2.1.0)
91
- rack (>= 3)
92
- webrick (~> 1.8)
93
- rails-dom-testing (2.2.0)
94
- activesupport (>= 5.0.0)
95
- minitest
96
- nokogiri (>= 1.6)
97
- rails-html-sanitizer (1.6.0)
98
- loofah (~> 2.21)
99
- nokogiri (~> 1.14)
100
- railties (7.2.0)
101
- actionpack (= 7.2.0)
102
- activesupport (= 7.2.0)
103
- irb (~> 1.13)
104
- rackup (>= 1.0.0)
105
- rake (>= 12.2)
106
- thor (~> 1.0, >= 1.2.2)
107
- zeitwerk (~> 2.6)
108
33
  rainbow (3.1.1)
109
- rake (13.2.1)
110
- rdoc (6.7.0)
111
- psych (>= 4.0.0)
112
- regexp_parser (2.9.2)
113
- reline (0.5.9)
114
- io-console (~> 0.5)
115
- rexml (3.3.5)
116
- strscan
117
- rspec-core (3.13.0)
118
- rspec-support (~> 3.13.0)
119
- rspec-expectations (3.13.1)
120
- diff-lcs (>= 1.2.0, < 2.0)
121
- rspec-support (~> 3.13.0)
122
- rspec-mocks (3.13.1)
123
- diff-lcs (>= 1.2.0, < 2.0)
124
- rspec-support (~> 3.13.0)
125
- rspec-rails (6.1.3)
126
- actionpack (>= 6.1)
127
- activesupport (>= 6.1)
128
- railties (>= 6.1)
129
- rspec-core (~> 3.13)
130
- rspec-expectations (~> 3.13)
131
- rspec-mocks (~> 3.13)
132
- rspec-support (~> 3.13)
133
- rspec-support (3.13.1)
134
- rubocop (1.65.1)
34
+ rake (13.3.0)
35
+ regexp_parser (2.10.0)
36
+ rexml (3.4.1)
37
+ rubocop (1.77.0)
135
38
  json (~> 2.3)
136
- language_server-protocol (>= 3.17.0)
39
+ language_server-protocol (~> 3.17.0.2)
40
+ lint_roller (~> 1.1.0)
137
41
  parallel (~> 1.10)
138
42
  parser (>= 3.3.0.2)
139
43
  rainbow (>= 2.2.2, < 4.0)
140
- regexp_parser (>= 2.4, < 3.0)
141
- rexml (>= 3.2.5, < 4.0)
142
- rubocop-ast (>= 1.31.1, < 2.0)
44
+ regexp_parser (>= 2.9.3, < 3.0)
45
+ rubocop-ast (>= 1.45.1, < 2.0)
143
46
  ruby-progressbar (~> 1.7)
144
- unicode-display_width (>= 2.4.0, < 3.0)
145
- rubocop-ast (1.32.0)
146
- parser (>= 3.3.1.0)
147
- rubocop-rspec (3.0.4)
148
- rubocop (~> 1.61)
47
+ unicode-display_width (>= 2.4.0, < 4.0)
48
+ rubocop-ast (1.45.1)
49
+ parser (>= 3.3.7.2)
50
+ prism (~> 1.4)
51
+ rubocop-minitest (0.38.1)
52
+ lint_roller (~> 1.1)
53
+ rubocop (>= 1.75.0, < 2.0)
54
+ rubocop-ast (>= 1.38.0, < 2.0)
55
+ rubocop-performance (1.25.0)
56
+ lint_roller (~> 1.1)
57
+ rubocop (>= 1.75.0, < 2.0)
58
+ rubocop-ast (>= 1.38.0, < 2.0)
59
+ rubocop-rake (0.7.1)
60
+ lint_roller (~> 1.1)
61
+ rubocop (>= 1.72.1)
149
62
  ruby-progressbar (1.13.0)
150
- securerandom (0.3.1)
151
63
  simplecov (0.22.0)
152
64
  docile (~> 1.1)
153
65
  simplecov-html (~> 0.11)
@@ -155,24 +67,19 @@ GEM
155
67
  simplecov-cobertura (2.1.0)
156
68
  rexml
157
69
  simplecov (~> 0.19)
158
- simplecov-html (0.12.3)
70
+ simplecov-html (0.13.1)
159
71
  simplecov_json_formatter (0.1.4)
160
- stringio (3.1.1)
161
- strscan (3.1.0)
162
- tago (0.0.2)
163
- thor (1.3.1)
164
- tzinfo (2.0.6)
165
- concurrent-ruby (~> 1.0)
166
- unicode-display_width (2.5.0)
167
- useragent (0.16.10)
168
- webrick (1.8.1)
169
- yard (0.9.36)
170
- zeitwerk (2.6.17)
72
+ tago (0.1.0)
73
+ unicode-display_width (3.1.4)
74
+ unicode-emoji (~> 4.0, >= 4.0.4)
75
+ unicode-emoji (4.0.4)
76
+ yard (0.9.37)
171
77
 
172
78
  PLATFORMS
173
79
  aarch64-linux
174
80
  arm-linux
175
81
  arm64-darwin
82
+ arm64-darwin-23
176
83
  x64-mingw-ucrt
177
84
  x86-linux
178
85
  x86_64-darwin
@@ -180,14 +87,16 @@ PLATFORMS
180
87
 
181
88
  DEPENDENCIES
182
89
  elapsed!
183
- minitest (= 5.25.0)
184
- rake (= 13.2.1)
185
- rspec-rails (= 6.1.3)
186
- rubocop (= 1.65.1)
187
- rubocop-rspec (= 3.0.4)
188
- simplecov (= 0.22.0)
189
- simplecov-cobertura (= 2.1.0)
190
- yard (= 0.9.36)
90
+ minitest (~> 5.25)
91
+ minitest-reporters (~> 1.7)
92
+ rake (~> 13.2)
93
+ rubocop (~> 1.69)
94
+ rubocop-minitest (~> 0.38)
95
+ rubocop-performance (~> 1.25)
96
+ rubocop-rake (~> 0.7)
97
+ simplecov (~> 0.22)
98
+ simplecov-cobertura (~> 2.1)
99
+ yard (~> 0.9)
191
100
 
192
101
  BUNDLED WITH
193
102
  2.5.16
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Measures the Time Elapsed by a Block
2
2
 
3
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/elapsed)](http://www.rultor.com/p/yegor256/elapsed)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/elapsed)](https://www.rultor.com/p/yegor256/elapsed)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/elapsed/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/elapsed/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/elapsed)](http://www.0pdd.com/p?name=yegor256/elapsed)
8
- [![Gem Version](https://badge.fury.io/rb/elapsed.svg)](http://badge.fury.io/rb/elapsed)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/elapsed)](https://www.0pdd.com/p?name=yegor256/elapsed)
8
+ [![Gem Version](https://badge.fury.io/rb/elapsed.svg)](https://badge.fury.io/rb/elapsed)
9
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/elapsed.svg)](https://codecov.io/github/yegor256/elapsed?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/elapsed/master/frames)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/elapsed/master/frames)
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/elapsed)](https://hitsofcode.com/view/github/yegor256/elapsed)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/elapsed/blob/master/LICENSE.txt)
13
13
 
@@ -34,7 +34,7 @@ end
34
34
  You can also make the message custom:
35
35
 
36
36
  ```ruby
37
- elapsed(intro: 'File saved') do
37
+ elapsed(good: 'File saved') do
38
38
  File.save(f, 'Hello, world!')
39
39
  end
40
40
  ```
@@ -54,7 +54,7 @@ That's it.
54
54
 
55
55
  Read
56
56
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
57
- Make sure you build is green before you contribute
57
+ Make sure your build is green before you contribute
58
58
  your pull request. You will need to have
59
59
  [Ruby](https://www.ruby-lang.org/en/) 3.0+ and
60
60
  [Bundler](https://bundler.io/) installed. Then:
data/REUSE.toml ADDED
@@ -0,0 +1,34 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.txt",
14
+ "**/.DS_Store",
15
+ "**/.gitignore",
16
+ "**/.pdd",
17
+ "**/*.csv",
18
+ "**/*.jpg",
19
+ "**/*.json",
20
+ "**/*.md",
21
+ "**/*.pdf",
22
+ "**/*.png",
23
+ "**/*.svg",
24
+ "**/*.txt",
25
+ "**/*.vm",
26
+ "**/CNAME",
27
+ "**/Gemfile.lock",
28
+ "Gemfile.lock",
29
+ "README.md",
30
+ "renovate.json",
31
+ ]
32
+ precedence = "override"
33
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
34
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'rubygems'
24
7
  require 'rake'
@@ -33,7 +16,7 @@ def version
33
16
  Gem::Specification.load(Dir['*.gemspec'].first).version
34
17
  end
35
18
 
36
- task default: %i[clean test rubocop yard copyright]
19
+ task default: %i[clean test rubocop yard]
37
20
 
38
21
  require 'rake/testtask'
39
22
  desc 'Run all unit tests'
@@ -55,14 +38,4 @@ require 'rubocop/rake_task'
55
38
  desc 'Run RuboCop on all directories'
56
39
  RuboCop::RakeTask.new(:rubocop) do |task|
57
40
  task.fail_on_error = true
58
- task.requires << 'rubocop-rspec'
59
- end
60
-
61
- task :copyright do
62
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
63
- --include '*.rb' \
64
- --include '*.yml' \
65
- --include '*.txt' \
66
- --include 'Rakefile' \
67
- ."
68
41
  end
data/elapsed.gemspec CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'English'
24
7
 
@@ -26,7 +9,7 @@ Gem::Specification.new do |s|
26
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
10
  s.required_ruby_version = '>=3.2'
28
11
  s.name = 'elapsed'
29
- s.version = '0.0.1'
12
+ s.version = '0.1.0'
30
13
  s.license = 'MIT'
31
14
  s.summary = 'A simple Ruby function to measure the time elapsed by the execution of a block'
32
15
  s.description =
@@ -34,7 +17,7 @@ Gem::Specification.new do |s|
34
17
  'print the summary of execution to the log with the time it took'
35
18
  s.authors = ['Yegor Bugayenko']
36
19
  s.email = 'yegor256@gmail.com'
37
- s.homepage = 'http://github.com/yegor256/elapsed'
20
+ s.homepage = 'https://github.com/yegor256/elapsed'
38
21
  s.files = `git ls-files`.split($RS)
39
22
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
40
23
  s.rdoc_options = ['--charset=UTF-8']
data/lib/elapsed.rb CHANGED
@@ -1,29 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'logger'
24
7
  require 'tago'
25
8
 
26
- # The function measures the time taked by a block to execute and then prints
9
+ # The function measures the time taken by a block to execute and then prints
27
10
  # it to the log.
28
11
  #
29
12
  # require 'elapsed'
@@ -33,40 +16,37 @@ require 'tago'
33
16
  # end
34
17
  #
35
18
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
36
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
19
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
37
20
  # License:: MIT
38
21
  #
39
22
  # @param [Object] log The log to send .debug() to
40
- # @param [String] intro The message to start with
23
+ # @param [String] good The message to print on success finish
24
+ # @param [String] bad The message to print on failure finish
41
25
  # @param [Integer] level The level of logging to use
42
- def elapsed(log = nil, intro: 'Finished', level: Logger::DEBUG)
26
+ def elapsed(log = nil, good: 'Finished', level: Logger::DEBUG, bad: 'Failed')
43
27
  start = Time.now
44
- begin
45
- ret = yield
46
- msg = intro.to_s
47
- msg += " in #{start.ago}"
28
+ print_it = lambda do |m|
29
+ m += " in #{start.ago}"
48
30
  if log.nil?
49
- puts msg
31
+ puts m
50
32
  elsif level == Logger::DEBUG
51
- log.debug(msg)
33
+ log.debug(m)
52
34
  elsif level == Logger::INFO
53
- log.info(msg)
35
+ log.info(m)
54
36
  else
55
- log.warn(msg)
37
+ log.warn(m)
56
38
  end
39
+ end
40
+ begin
41
+ ret = yield
42
+ print_it.call(good.to_s)
57
43
  ret
58
44
  rescue UncaughtThrowError => e
59
45
  tag = e.tag
60
46
  throw e unless tag.is_a?(Symbol)
61
- msg = "#{tag} in #{start.ago}"
62
- if log.nil?
63
- puts msg
64
- elsif level == Logger::DEBUG
65
- log.debug(msg)
66
- elsif level == Logger::INFO
67
- log.info(msg)
68
- else
69
- log.warn(msg)
70
- end
47
+ print_it.call(tag.to_s)
48
+ rescue StandardError => e
49
+ print_it.call(bad.to_s)
50
+ raise e
71
51
  end
72
52
  end
data/test/test__helper.rb CHANGED
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  $stdout.sync = true
24
7
 
25
8
  require 'simplecov'
26
- SimpleCov.start
27
-
28
9
  require 'simplecov-cobertura'
29
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
10
+ unless SimpleCov.running
11
+ SimpleCov.command_name('test')
12
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
13
+ [
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ SimpleCov::Formatter::CoberturaFormatter
16
+ ]
17
+ )
18
+ SimpleCov.minimum_coverage 100
19
+ SimpleCov.minimum_coverage_by_file 100
20
+ SimpleCov.start do
21
+ add_filter 'test/'
22
+ add_filter 'vendor/'
23
+ add_filter 'target/'
24
+ track_files 'lib/**/*.rb'
25
+ track_files '*.rb'
26
+ end
27
+ end
30
28
 
31
29
  require 'minitest/autorun'
30
+ require 'minitest/reporters'
31
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
data/test/test_elapsed.rb CHANGED
@@ -1,42 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
- require 'minitest/autorun'
24
6
  require 'loog'
7
+ require_relative 'test__helper'
25
8
  require_relative '../lib/elapsed'
26
9
 
27
10
  # Test.
28
11
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
12
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
30
13
  # License:: MIT
31
14
  class TestElapsed < Minitest::Test
32
15
  def test_simple
33
16
  loog = Loog::Buffer.new
34
17
  r =
35
- elapsed(loog, intro: 'Everything was good') do
18
+ elapsed(loog, good: 'Everything was good') do
36
19
  4 + 5
37
20
  end
38
21
  assert_equal(9, r)
39
- assert(loog.to_s.include?('was good'))
22
+ assert_includes(loog.to_s, 'was good')
23
+ end
24
+
25
+ def test_with_failure
26
+ loog = Loog::Buffer.new
27
+ assert_raises(StandardError) do
28
+ elapsed(loog, bad: 'Failed miserably') do
29
+ raise 'oops'
30
+ end
31
+ end
40
32
  end
41
33
 
42
34
  def test_with_throw
@@ -44,7 +36,7 @@ class TestElapsed < Minitest::Test
44
36
  elapsed(loog) do
45
37
  throw :'Perfectly works'
46
38
  end
47
- assert(loog.to_s.include?('works'))
39
+ assert_includes(loog.to_s, 'works')
48
40
  end
49
41
 
50
42
  def test_to_stdout