minitest-utils 0.6.4 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7c7da3098f0a0728f25348e09ef0ac6452d239e8c16c0e00db3325ec706821
4
- data.tar.gz: 3dcea89d7a09595f96773f7ce43c1f34b331f8c80219b7813f750549051ca1a8
3
+ metadata.gz: e8a6552a933ed30c1aa6bc204b5202e7a4e97b6ee131ec1beca251df903c86ff
4
+ data.tar.gz: dd6d52f1f5dfb48b999c351439cb3ea399d19fbd0fae0215778987207914cd1f
5
5
  SHA512:
6
- metadata.gz: 4d61f801823c3e939f975318987e0cd1566bf2bf617487709bc1b0663be2e1ebc28ed3d8487f4879a570406ce2cf803497ed9199e81dedd9ca2aa7b5b0d372c7
7
- data.tar.gz: fc2a64b7bdde0bd3945de4ece997ccf69802afe368bc66c5c751f4656fa45e3d2ac6eb7415f78873722f59cf8e5e03d83beb9974e4ba6a9f6a8d30bc51cd3bac
6
+ metadata.gz: 419d5dcc979dced369d4608d8320e596290645bc62914ed1e28df19999c560146dfbaf720fed8d4efeb9cc0a85b2db93b3bb23ae494ddf426899ab1c7898c5f6
7
+ data.tar.gz: beda5a34b0123a798ac3fb3ac625b9e88b008e4aba0e2bfea773fb0902f7b8412bf81d543fe45a446cd4b7280e47393fb9ce50bbce2a5b15f806eb6d7f6857ce
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in minitest-utils.gemspec
6
6
  gemspec
7
+ gem "test_notifier"
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/utils"
4
+
5
+ load_lib = lambda do |path, &block|
6
+ require path
7
+ block&.call
8
+ true
9
+ rescue LoadError
10
+ false
11
+ end
12
+
13
+ load_lib.call "mocha/mini_test" unless load_lib.call "mocha/minitest"
14
+
15
+ load_lib.call "capybara"
16
+
17
+ load_lib.call "webmock" do
18
+ require_relative "utils/setup/webmock"
19
+ end
20
+
21
+ load_lib.call "database_cleaner" do
22
+ require_relative "utils/setup/database_cleaner"
23
+ end
24
+
25
+ load_lib.call "factory_girl" do
26
+ require_relative "utils/setup/factory_girl"
27
+ end
28
+
29
+ load_lib.call "factory_bot" do
30
+ require_relative "utils/setup/factory_bot"
31
+ end
32
+
33
+ require_relative "utils/railtie" if defined?(Rails)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  gem "selenium-webdriver"
4
- gem "chromedriver-helper"
4
+ gem "webdrivers"
5
5
 
6
6
  Capybara.register_driver :chrome do |app|
7
7
  options = Selenium::WebDriver::Chrome::Options.new(
@@ -113,7 +113,7 @@ module Minitest
113
113
 
114
114
  bundler = "bundle exec " if self.class.loaded_via_bundle_exec
115
115
 
116
- ENV["MT_TEST_COMMAND"] =
116
+ ENV["MT_TEST_COMMAND"] ||=
117
117
  "#{bundler}mt %{location}:%{line} #{color('# %{description}', :blue)}"
118
118
 
119
119
  ARGV.clear
@@ -374,7 +374,7 @@ module Minitest
374
374
  io << "\n"
375
375
 
376
376
  matches.each do |match|
377
- match => { short:, long:, description: }
377
+ match => {short:, long:, description:}
378
378
 
379
379
  io << " "
380
380
  io << (" " * (short_size - short.to_s.size))
@@ -12,6 +12,42 @@ module Minitest
12
12
  message ||= "expected: falsy value\ngot: #{mu_pp(test)}"
13
13
  super
14
14
  end
15
+
16
+ def diff(expected, actual)
17
+ expected = mu_pp_for_diff(expected)
18
+ actual = mu_pp_for_diff(actual)
19
+
20
+ a = expected.scan(/\w+|\W+/)
21
+ b = actual.scan(/\w+|\W+/)
22
+
23
+ exp_out = +""
24
+ act_out = +""
25
+
26
+ Diff::LCS
27
+ .sdiff(a, b)
28
+ .chunk_while {|a, b| a.action == b.action }
29
+ .each do |group|
30
+ action = group.first.action
31
+ old_str = group.filter_map(&:old_element).join
32
+ new_str = group.filter_map(&:new_element).join
33
+
34
+ case action
35
+ when "="
36
+ exp_out << old_str
37
+ act_out << new_str
38
+ when "-"
39
+ exp_out << Utils.color(old_str, :red, bgcolor: :red)
40
+ when "+"
41
+ act_out << Utils.color(new_str, :green, bgcolor: :green)
42
+ when "!"
43
+ exp_out << Utils.color(old_str, :red, bgcolor: :red)
44
+ act_out << Utils.color(new_str, :green, bgcolor: :green)
45
+ end
46
+ end
47
+
48
+ "#{Utils.color('expected: ', :red)} #{exp_out}\n" \
49
+ "#{Utils.color(' actual: ', :red)} #{act_out}"
50
+ end
15
51
  end
16
52
  end
17
53
 
@@ -37,6 +73,37 @@ module Minitest
37
73
  :"test_#{method_name}"
38
74
  end
39
75
 
76
+ # This hook handles methods defined directly with `def test_`.
77
+ def self.method_added(method_name)
78
+ super
79
+
80
+ test_name = method_name.to_s
81
+
82
+ return unless test_name.start_with?("test_")
83
+
84
+ klass = name
85
+ id = "#{klass}##{method_name}"
86
+ description = method_name.to_s.delete_prefix("test_").tr("_", " ")
87
+
88
+ return if Test.tests[id]
89
+
90
+ file_path, lineno = instance_method(method_name).source_location
91
+
92
+ source_location = [
93
+ Pathname(file_path).relative_path_from(Pathname(Dir.pwd)),
94
+ lineno
95
+ ]
96
+
97
+ Test.tests[id] = {
98
+ id:,
99
+ description:,
100
+ name: test_name,
101
+ source_location:,
102
+ time: nil,
103
+ slow_threshold:
104
+ }
105
+ end
106
+
40
107
  def self.test(description, &block)
41
108
  source_location = caller_locations(1..1).first
42
109
  source_location = [
@@ -115,7 +115,7 @@ module Minitest
115
115
  results
116
116
  .each
117
117
  .with_index(initial_index + 1) do |result, index|
118
- display_skipped(result, index)
118
+ display_skipped(result, index)
119
119
  end
120
120
  end
121
121
 
@@ -293,8 +293,8 @@ module Minitest
293
293
 
294
294
  private def running_rails?
295
295
  defined?(Rails) &&
296
- Rails.respond_to?(:version) &&
297
- Rails.version >= "5.0.0"
296
+ Rails.respond_to?(:version) &&
297
+ Rails.version >= "5.0.0"
298
298
  end
299
299
 
300
300
  def bundler
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Utils
5
- VERSION = "0.6.4"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
@@ -10,26 +10,22 @@ module Minitest
10
10
  module Utils
11
11
  require "minitest"
12
12
  require "pathname"
13
+ require "diff/lcs"
13
14
  require_relative "utils/version"
14
15
  require_relative "utils/reporter"
15
16
  require_relative "utils/extension"
16
- require_relative "utils/test_notifier_reporter"
17
-
18
- COLOR = {
19
- red: 31,
20
- green: 32,
21
- yellow: 33,
22
- blue: 34,
23
- gray: 37
24
- }.freeze
25
-
26
- def self.color(string, color = :default)
27
- if color_enabled?
28
- color = COLOR.fetch(color, 0)
29
- "\e[#{color}m#{string}\e[0m"
30
- else
31
- string
32
- end
17
+
18
+ COLOR = {red: 31, green: 32, yellow: 33, blue: 34, gray: 37}.freeze
19
+ BGCOLOR = {red: 41, green: 42, yellow: 43, blue: 44, gray: 47}.freeze
20
+
21
+ def self.color(string, color = :default, bgcolor: nil)
22
+ return string unless color_enabled?
23
+
24
+ fg = COLOR.fetch(color, 0)
25
+ bg = BGCOLOR.fetch(bgcolor, nil)
26
+
27
+ code = [fg, bg].compact.join(";")
28
+ "\e[#{code}m#{string}\e[0m"
33
29
  end
34
30
 
35
31
  def self.color_enabled?
@@ -65,5 +61,7 @@ module Minitest
65
61
  end
66
62
 
67
63
  require_relative "utils/railtie" if defined?(Rails)
64
+
65
+ Minitest.load(:utils)
68
66
  end
69
67
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "utils/reporter"
4
- require_relative "utils/test_notifier_reporter"
5
4
 
6
5
  module Minitest
7
6
  def self.plugin_utils_options(opts, options)
@@ -36,10 +35,6 @@ module Minitest
36
35
 
37
36
  begin
38
37
  require "test_notifier"
39
- reporters << Minitest::Utils::TestNotifierReporter.new(
40
- options[:io],
41
- options
42
- )
43
38
  rescue LoadError
44
39
  # noop
45
40
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "diff-lcs"
22
23
  spec.add_dependency "listen"
23
24
  spec.add_dependency "minitest"
24
25
  spec.add_development_dependency "bundler"
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: diff-lcs
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: listen
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +158,7 @@ files:
144
158
  - exe/minitest
145
159
  - exe/mt
146
160
  - lib/minitest/utils.rb
161
+ - lib/minitest/utils/autoload.rb
147
162
  - lib/minitest/utils/capybara/chrome_headless.rb
148
163
  - lib/minitest/utils/cli.rb
149
164
  - lib/minitest/utils/extension.rb
@@ -156,7 +171,6 @@ files:
156
171
  - lib/minitest/utils/setup/factory_bot.rb
157
172
  - lib/minitest/utils/setup/factory_girl.rb
158
173
  - lib/minitest/utils/setup/webmock.rb
159
- - lib/minitest/utils/test_notifier_reporter.rb
160
174
  - lib/minitest/utils/version.rb
161
175
  - lib/minitest/utils_plugin.rb
162
176
  - minitest-utils.gemspec
@@ -182,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
196
  - !ruby/object:Gem::Version
183
197
  version: '0'
184
198
  requirements: []
185
- rubygems_version: 3.6.2
199
+ rubygems_version: 4.0.3
186
200
  specification_version: 4
187
201
  summary: Some utilities for your Minitest day-to-day usage.
188
202
  test_files: []
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Minitest
4
- module Utils
5
- class TestNotifierReporter < Minitest::StatisticsReporter
6
- def report
7
- super
8
-
9
- stats = TestNotifier::Stats.new(:minitest,
10
- count: count,
11
- assertions: assertions,
12
- failures: failures,
13
- errors: errors)
14
-
15
- TestNotifier.notify(status: stats.status, message: stats.message)
16
- end
17
- end
18
- end
19
- end