nicetest 0.1.2 → 0.1.5

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: ca570cb158012e0e98984c7abf67f6aa92b2653bda115e6ce933287854ef269d
4
- data.tar.gz: 551b0ba37750778871181487bae3f9c17d0a8dbb662d0e94b1967191c753483f
3
+ metadata.gz: bd840baef344a54b96b5b2cb3d6a21c70a3d2b4c497bee0fc6c3f963a839d7b1
4
+ data.tar.gz: dc0847ffd7f0c3b17c6e4f284e5cfad2688eed8e9d123f65b2311ae508321ec2
5
5
  SHA512:
6
- metadata.gz: 397a83bad37cedcce9c4804872c6d8f749ba3ded816e26767fa056260d6145e44373b2dd59409e55e1ddced29a3090dbe676adcb548b54c8b8f43a2dbc2970d9
7
- data.tar.gz: 23d3fccdca0763553f62e9be37d60079d869aefa71c861c9518a9db1de2ff52496d5b100727ad7bd0d5a297fb768d0b9a1ac361e43f1f1c0f44c1d6209d76bcc
6
+ metadata.gz: e427bd82c9fe9b3b22d42ccf9cbbbbb5c89d63ed883eabb0b401157f39808ac9d13f89825f207158c11b46fb3f330b7462c64b2d29b6b23c8933a2fd3c958db8
7
+ data.tar.gz: 2484e985c2547e91a2a4b636711ae4b48d809cf18e7f6503f94de2a30cbd3489b1e2077bc4c71989dfbc9db81043dad2ab2d4d422ae9ca87c81d9e19e1e5390a
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- C;�횦�6zL`�v����z�_�G�s�
2
- ��ԞR¼�a��2�xd���I7�ov.�� S���ddMk��e=Ť�R�CD�� V�+�@�.� q�T�ʥ�c��V��u{�f�D4
1
+ Gm/����nL*�����`
data/README.md CHANGED
@@ -26,19 +26,35 @@ $ gem install nicetest
26
26
  # Go into a repo
27
27
  $ git clone https://github.com/Shopfy/liquid; cd liquid; bundle install
28
28
 
29
- # Run the tests
30
- $ nicetest --reporter doc test/integration/capture_test.rb
31
- Started with run options --reporter doc --seed 12874
29
+ # Run a test
30
+ nicetest --reporter doc test/integration/capture_test.rb:14
31
+ Started with run options --reporter doc --name=/CaptureTest#test_capture_with_hyphen_in_variable_name/ --seed 24518
32
32
 
33
33
  CaptureTest
34
- test_increment_assign_score_by_bytes_not_characters PASS (0.00s)
35
- test_captures_block_content_in_variable PASS (0.00s)
36
- test_capture_to_variable_from_outer_scope_if_existing PASS (0.00s)
37
- test_assigning_from_capture PASS (0.00s)
38
34
  test_capture_with_hyphen_in_variable_name PASS (0.00s)
39
35
 
40
- Finished in 0.00123s
41
- 5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
36
+ Finished in 0.00115s
37
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
38
+
39
+ # JUnit is easy
40
+ ❯ nicetest --reporter junit,progress
41
+ Emptying /Users/ianks/Code/Shopify/liquid/tmp/nicetest/junit/1721874837
42
+ Started with run options --reporter junit,progress --seed 36139
43
+
44
+ 799/799: [================================================================================] 100% Time: 00:00:00, Time: 00:00:00
45
+ Writing XML reports to /Users/ianks/Code/Shopify/liquid/tmp/nicetest/junit/1721874837
46
+
47
+ Finished in 0.94625s
48
+ 799 tests, 1924 assertions, 0 failures, 0 errors, 0 skips
49
+
50
+ # Filter by name
51
+ ❯ nicetest --name=/assign/
52
+ Started with run options --name=/assign/ --seed 44734
53
+
54
+ 33/33: [====================================================================================] 100% Time: 00:00:00, Time: 00:00:00
55
+
56
+ Finished in 0.03157s
57
+ 33 tests, 69 assertions, 0 failures, 0 errors, 0 skips
42
58
  ```
43
59
 
44
60
  ### Add to project
@@ -86,6 +102,14 @@ task :test do
86
102
  end
87
103
  ```
88
104
 
105
+ ## Recognition
106
+
107
+ - [minitest] for superb testing
108
+ - [minitest-reporters] for the excellent reporting
109
+ - [super_diff] for the pretty diffs
110
+ - [prism] for the blissful parser
111
+ - [pastel] for the pretty colors
112
+
89
113
  ## Contributing
90
114
 
91
115
  Bug reports and pull requests are welcome on GitHub at
@@ -95,3 +119,9 @@ https://github.com/ianks/nicetest.
95
119
 
96
120
  The gem is available as open source under the terms of the [MIT
97
121
  License](https://opensource.org/licenses/MIT).
122
+
123
+ [minitest]: https://github.com/minitest/minitest
124
+ [minitest-reporters]: https://github.com/minitest-reporters/minitest-reporters
125
+ [super_diff]: https://github.com/mcmire/super_diff
126
+ [prism]: https://github.com/ruby/prism
127
+ [pastel]: https://github.com/piotrmurach/pastel
@@ -6,14 +6,18 @@ require "nicetest"
6
6
  module Minitest
7
7
  class << self
8
8
  def plugin_nicetest_options(opts, options)
9
- opts.banner = Nicetest::Cli::BANNER
10
- ValidateMinitestFocus.apply!
9
+ opts.banner = ::Nicetest::Cli::BANNER
10
+ Nicetest::NicetestPlugin::ValidateMinitestFocus.apply!
11
11
  end
12
12
 
13
13
  def plugin_nicetest_init(_options)
14
14
  Minitest.backtrace_filter = Nicetest::BacktraceFilter.new
15
15
  end
16
+ end
17
+ end
16
18
 
19
+ module Nicetest
20
+ module NicetestPlugin
17
21
  module ValidateMinitestFocus
18
22
  class << self
19
23
  def apply!
@@ -1,25 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minitest
4
- module ReportersPlugin
5
- MAPPING ||= {
6
- "none" => ->(_options) { nil },
7
- "default" => ->(options) { Minitest::Reporters::DefaultReporter.new(io: options[:io]) },
8
- "spec" => ->(options) { Minitest::Reporters::SpecReporter.new(io: options[:io]) },
9
- "doc" => ->(options) { MAPPING["spec"].call(options) },
10
- "junit" => ->(options) {
11
- ENV["MINITEST_REPORTERS_REPORTS_DIR"] ||= "tmp/nicetest/junit/#{Time.now.to_i}"
12
- Minitest::Reporters::JUnitReporter.new(io: options[:io])
13
- },
14
- "progress" => ->(options) { Minitest::Reporters::ProgressReporter.new(io: options[:io]) },
15
- }
16
- end
17
-
18
4
  class << self
19
5
  def plugin_reporters_options(opts, options)
20
6
  options[:reporters] = ["progress"]
21
7
 
22
- vals = Minitest::ReportersPlugin::MAPPING.keys.join(",")
8
+ vals = Nicetest::ReportersPlugin::MAPPING.keys.join(",")
23
9
  description = <<~DESC.strip
24
10
  The reporters to use for test output as comma-seperated list.
25
11
  DESC
@@ -27,7 +13,7 @@ module Minitest
27
13
  opts.on("-r", "--reporter #{vals}", Array, description) do |reporters|
28
14
  reporters = options[:reporters] + reporters if reporters == ["junit"]
29
15
 
30
- is_subset = (reporters - Minitest::ReportersPlugin::MAPPING.keys).empty?
16
+ is_subset = (reporters - Nicetest::ReportersPlugin::MAPPING.keys).empty?
31
17
  raise OptionParser::InvalidArgument, "Invalid reporter: #{reporters.join(", ")}" unless is_subset
32
18
 
33
19
  options[:reporters] = reporters
@@ -40,10 +26,26 @@ module Minitest
40
26
  require "minitest/reporters"
41
27
 
42
28
  reporters = options[:reporters].map do |reporter|
43
- ReportersPlugin::MAPPING.fetch(reporter).call(options)
29
+ Nicetest::ReportersPlugin::MAPPING.fetch(reporter).call(options)
44
30
  end.compact
45
31
 
46
32
  Minitest::Reporters.use!(reporters, ENV, Minitest.backtrace_filter) unless reporters.empty?
47
33
  end
48
34
  end
49
35
  end
36
+
37
+ module Nicetest
38
+ module ReportersPlugin
39
+ MAPPING = {
40
+ "none" => ->(_options) { nil },
41
+ "default" => ->(options) { Minitest::Reporters::DefaultReporter.new(io: options[:io]) },
42
+ "spec" => ->(options) { Minitest::Reporters::SpecReporter.new(io: options[:io]) },
43
+ "doc" => ->(options) { MAPPING["spec"].call(options) },
44
+ "junit" => ->(options) {
45
+ ENV["MINITEST_REPORTERS_REPORTS_DIR"] ||= "tmp/nicetest/junit/#{Time.now.to_i}"
46
+ Minitest::Reporters::JUnitReporter.new(io: options[:io])
47
+ },
48
+ "progress" => ->(options) { Minitest::Reporters::ProgressReporter.new(io: options[:io]) },
49
+ }
50
+ end
51
+ end
@@ -12,13 +12,16 @@ module Minitest
12
12
  return if options[:no_superdiff]
13
13
 
14
14
  require "super_diff"
15
- Minitest::Assertions.prepend(SuperdiffPlugin)
15
+ Minitest::Assertions.prepend(Nicetest::SuperdiffPlugin)
16
16
  end
17
17
  end
18
+ end
18
19
 
20
+ module Nicetest
19
21
  module SuperdiffPlugin
20
22
  module Helpers
21
23
  extend self
24
+
22
25
  def inspect_styled(obj, style, prefix: nil)
23
26
  obj = SuperDiff.inspect_object(obj, as_lines: false)
24
27
  SuperDiff::Core::Helpers.style(style, "#{prefix}#{obj}")
@@ -42,54 +45,54 @@ module Minitest
42
45
  exception.set_backtrace(e.backtrace)
43
46
  raise exception
44
47
  end
45
- end
46
48
 
47
- class AssertIncludesMessage
48
- include SuperdiffPlugin::Helpers
49
+ class AssertIncludesMessage
50
+ include SuperdiffPlugin::Helpers
49
51
 
50
- def initialize(collection:, item:)
51
- @collection = collection
52
- @item = item
53
- end
52
+ def initialize(collection:, item:)
53
+ @collection = collection
54
+ @item = item
55
+ end
54
56
 
55
- def to_s
56
- return @to_s if defined?(@to_s)
57
+ def to_s
58
+ return @to_s if defined?(@to_s)
57
59
 
58
- content = if (diff = optional_diff)
59
- collection = inspect_styled(@collection, :expected)
60
- item = inspect_styled(@item, :actual)
60
+ content = if (diff = optional_diff)
61
+ collection = inspect_styled(@collection, :expected)
62
+ item = inspect_styled(@item, :actual)
61
63
 
62
- <<~OUTPUT.strip
63
- Expected #{collection} to include #{item}, but it did not.
64
+ <<~OUTPUT.strip
65
+ Expected #{collection} to include #{item}, but it did not.
64
66
 
65
- #{diff}
66
- OUTPUT
67
- else
68
- expected = inspect_styled(@collection, :expected, prefix: " Collection: ")
69
- actual = inspect_styled(@item, :actual, prefix: "Missing item: ")
67
+ #{diff}
68
+ OUTPUT
69
+ else
70
+ expected = inspect_styled(@collection, :expected, prefix: " Collection: ")
71
+ actual = inspect_styled(@item, :actual, prefix: "Missing item: ")
70
72
 
71
- <<~OUTPUT.strip
72
- Expected collection to include item but it did not.
73
+ <<~OUTPUT.strip
74
+ Expected collection to include item but it did not.
73
75
 
74
- #{expected}
75
- #{actual}
76
- OUTPUT
77
- end
76
+ #{expected}
77
+ #{actual}
78
+ OUTPUT
79
+ end
78
80
 
79
- @to_s ||= content
80
- end
81
+ @to_s ||= content
82
+ end
81
83
 
82
- def optional_diff
83
- case @collection
84
- when Array, Set
85
- collection_with_item = @collection + [@item].flatten(1)
86
- basic_diff(@collection, collection_with_item)
84
+ def optional_diff
85
+ case @collection
86
+ when Array, Set
87
+ collection_with_item = @collection + [@item].flatten(1)
88
+ basic_diff(@collection, collection_with_item)
89
+ end
87
90
  end
88
- end
89
91
 
90
- def basic_diff(expected, actual)
91
- content = SuperDiff.diff(expected, actual)
92
- "\nDiff:\n\n#{content}"
92
+ def basic_diff(expected, actual)
93
+ content = SuperDiff.diff(expected, actual)
94
+ "\nDiff:\n\n#{content}"
95
+ end
93
96
  end
94
97
  end
95
98
  end
data/lib/nicetest/cli.rb CHANGED
@@ -9,8 +9,10 @@ require "set"
9
9
  module Nicetest
10
10
  class Cli
11
11
  def initialize(argv)
12
+ @original_argv = argv.dup
12
13
  @argv = argv
13
14
  @logger = Logger.new($stderr)
15
+ adjust_load_path!
14
16
  end
15
17
 
16
18
  def run
@@ -26,7 +28,6 @@ module Nicetest
26
28
 
27
29
  def run_tests(cli_options = Opts.parse!(@argv))
28
30
  disable_autorun!
29
- adjust_load_path!
30
31
 
31
32
  args = @argv.dup
32
33
  argv_test_files = select_file_args(args)
@@ -42,6 +43,10 @@ module Nicetest
42
43
  filters << name
43
44
  end
44
45
 
46
+ # Gross hack to allow for plugins to be loaded before we require the test files
47
+ Minitest.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
48
+ processed_args = Minitest.process_args(args)
49
+
45
50
  required_files = argv_test_files.map do |pattern|
46
51
  file_or_dir, filter = finder.filter_for(pattern)
47
52
  filters << filter if filter && !cli_options.name
@@ -49,13 +54,30 @@ module Nicetest
49
54
  end
50
55
 
51
56
  @logger.fatal!("no test files found") if required_files.compact.empty?
52
- args << "--name=/#{filters.to_a.join("|")}/" if filters.any?
57
+
58
+ if filters.any?
59
+ processed_args[:filter] = Regexp.union(*filters.map do |source|
60
+ Regexp.new(source)
61
+ end)
62
+
63
+ processed_args[:args] = "#{processed_args[:args]} --name=/#{processed_args[:filter].source}/"
64
+ end
65
+
66
+ patch_minitest_process_args!(processed_args)
53
67
 
54
68
  Minitest.run(args)
55
69
  end
56
70
 
57
71
  private
58
72
 
73
+ def patch_minitest_process_args!(preprocessed)
74
+ original_process_args = Minitest.method(:process_args)
75
+ Minitest.define_singleton_method(:process_args) do |_input_args|
76
+ Minitest.define_singleton_method(:process_args, original_process_args)
77
+ preprocessed
78
+ end
79
+ end
80
+
59
81
  def fetch_dep_loadpaths(gemspec, seen = {})
60
82
  return [] if seen[gemspec.name]
61
83
 
@@ -87,7 +109,8 @@ module Nicetest
87
109
 
88
110
  loadpaths = fetch_dep_loadpaths(Gem.loaded_specs["nicetest"]).map { |path| "-I#{path}" }
89
111
  requires = ["-rnicetest"]
90
- args_with_removed_leading_path = @argv.map do |arg|
112
+ includes = ["-I#{dir}/test"]
113
+ args_with_removed_leading_path = @original_argv.map do |arg|
91
114
  arg = arg.dup
92
115
  arg.delete_prefix!(dir)
93
116
  arg.delete_prefix!(File.expand_path(dir))
@@ -102,6 +125,7 @@ module Nicetest
102
125
  RbConfig.ruby,
103
126
  *loadpaths,
104
127
  *requires,
128
+ *includes,
105
129
  "-e",
106
130
  "exit(Nicetest::Cli.new(ARGV).run_tests)",
107
131
  "--",
@@ -123,7 +147,7 @@ module Nicetest
123
147
 
124
148
  def select_file_args(args)
125
149
  args = args.dup
126
- Minitest.instance_variable_set(:@extensions, Set.new) # Avoid double-loading plugins
150
+ Minitest.instance_variable_set(:@extensions, Set.new(Minitest.extensions)) # Avoid double-loading plugins
127
151
  Minitest.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
128
152
  # this will remove all options from the args array
129
153
  temporarily_disable_optparse_callbacks { Minitest.process_args(args) }
@@ -131,14 +155,17 @@ module Nicetest
131
155
  end
132
156
 
133
157
  def glob_test_files(dir)
134
- Dir.glob("#{dir}/**{,/*/**}/*_test.rb")
158
+ Dir[
159
+ "#{dir}/**/test_*.rb",
160
+ "#{dir}/**/*_{test,spec}.rb",
161
+ ]
135
162
  end
136
163
 
137
164
  def require_path_or_dir(path_or_dir)
138
165
  if path_or_dir.end_with?(".rb")
139
166
  [try_require(path_or_dir)]
140
167
  else
141
- Dir.glob("#{path_or_dir}/**{,/*/**}/*_test.rb").map do |f|
168
+ glob_test_files(path_or_dir).map do |f|
142
169
  try_require(f)
143
170
  end
144
171
  end
@@ -159,7 +186,8 @@ module Nicetest
159
186
  end
160
187
 
161
188
  def adjust_load_path!
162
- $LOAD_PATH.unshift(File.expand_path("test"))
189
+ $LOAD_PATH.unshift(File.expand_path("test")) unless @adjusted
190
+ @adjusted = true
163
191
  end
164
192
 
165
193
  def temporarily_disable_optparse_callbacks(&blk)
@@ -190,9 +218,8 @@ module Nicetest
190
218
  options[:cd] = dir
191
219
  end
192
220
 
193
- opts.on("--version", "Show the version") do
194
- puts "nicetest #{Nicetest::VERSION}"
195
- exit
221
+ opts.on("-n", "--name=PATTERN", "Filter test names on pattern") do |pattern|
222
+ options[:name] = pattern
196
223
  end
197
224
  end
198
225
 
@@ -23,7 +23,8 @@ module Nicetest
23
23
 
24
24
  def find_test(filename, lineno)
25
25
  range_finder = @parse_cache[filename] ||= RangeFinder.parse_file(filename)
26
- range_finder.nearest_test_for_line(lineno)
26
+ regexp = range_finder.nearest_test_for_line(lineno)
27
+ "^#{regexp}$" if regexp
27
28
  rescue => e
28
29
  Nicetest.logger.warn("Failed to parse #{filename} (#{e.class}: #{e.message})")
29
30
  nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nicetest
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/nicetest.rb CHANGED
@@ -8,6 +8,9 @@ require_relative "nicetest/logger"
8
8
  require_relative "nicetest/cli"
9
9
  require_relative "nicetest/backtrace_filter"
10
10
  require_relative "nicetest/test_finder"
11
+ require_relative "minitest/nicetest_plugin"
12
+ require_relative "minitest/reporters_plugin"
13
+ require_relative "minitest/superdiff_plugin"
11
14
 
12
15
  module Nicetest
13
16
  class Error < StandardError; end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nicetest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -29,8 +29,50 @@ cert_chain:
29
29
  Lvd35BNvZkhFzs9xfykhurpkT2TiP2F3ZFn9dwLXMFe41pwrtEYLIWhYi8mUG4Ek
30
30
  6aR8M/tqIpChVV39
31
31
  -----END CERTIFICATE-----
32
- date: 2024-07-25 00:00:00.000000000 Z
32
+ date: 2025-01-11 00:00:00.000000000 Z
33
33
  dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: base64
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bigdecimal
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: logger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
34
76
  - !ruby/object:Gem::Dependency
35
77
  name: minitest
36
78
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
212
  - !ruby/object:Gem::Version
171
213
  version: '0'
172
214
  requirements: []
173
- rubygems_version: 3.5.9
215
+ rubygems_version: 3.5.22
174
216
  signing_key:
175
217
  specification_version: 4
176
218
  summary: A slightly fancier configuration for Minitest
metadata.gz.sig CHANGED
Binary file