nicetest 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -2
- data/README.md +39 -9
- data/lib/minitest/nicetest_plugin.rb +6 -2
- data/lib/minitest/reporters_plugin.rb +19 -17
- data/lib/minitest/superdiff_plugin.rb +40 -37
- data/lib/nicetest/cli.rb +34 -9
- data/lib/nicetest/version.rb +1 -1
- data/lib/nicetest.rb +3 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5039d33254ce5a534e39a585909dceefe1dd3bcc40dbbf406700b952f293264
|
4
|
+
data.tar.gz: 7a80a7e24b2d5ce333362f2b3ba929aa181e8112cd11dfec9a63799632f53a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad2f7a6140d4a536bed67b234b66af9af985faa3f87b09aeda005ae71318b0f2d72a5af657a1edb79ff01913f0a02e1f7e7d736f0da8c98909076f9a5a60532
|
7
|
+
data.tar.gz: 6443e1ca210c7f3ad4bf19e06c3590baa59cb163fbae978c6315e87366ae20a1fb446f70dfe90b5c6d64037fa063680b4618a1ffc2b1e6350e208cf56dc6d2a4
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
�
|
2
|
-
|
1
|
+
0�l.┧@^��U�m���KjO�@��;����Td�x��Fd@�},w<Ly�I�5g��ʶ�{��nF�Ξ�{0�犫}��m����^����K�� �8�)#$���1�J��2y_�h9�1ф- El�a��7~^
|
2
|
+
������
|
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
|
30
|
-
|
31
|
-
Started with run options --reporter doc --seed
|
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.
|
41
|
-
|
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 =
|
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 -
|
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
|
-
|
48
|
-
|
49
|
+
class AssertIncludesMessage
|
50
|
+
include SuperdiffPlugin::Helpers
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def initialize(collection:, item:)
|
53
|
+
@collection = collection
|
54
|
+
@item = item
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
def to_s
|
58
|
+
return @to_s if defined?(@to_s)
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
content = if (diff = optional_diff)
|
61
|
+
collection = inspect_styled(@collection, :expected)
|
62
|
+
item = inspect_styled(@item, :actual)
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
+
<<~OUTPUT.strip
|
65
|
+
Expected #{collection} to include #{item}, but it did not.
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
73
|
+
<<~OUTPUT.strip
|
74
|
+
Expected collection to include item but it did not.
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
#{expected}
|
77
|
+
#{actual}
|
78
|
+
OUTPUT
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
+
@to_s ||= content
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
@@ -11,6 +11,7 @@ module Nicetest
|
|
11
11
|
def initialize(argv)
|
12
12
|
@argv = argv
|
13
13
|
@logger = Logger.new($stderr)
|
14
|
+
adjust_load_path!
|
14
15
|
end
|
15
16
|
|
16
17
|
def run
|
@@ -26,7 +27,6 @@ module Nicetest
|
|
26
27
|
|
27
28
|
def run_tests(cli_options = Opts.parse!(@argv))
|
28
29
|
disable_autorun!
|
29
|
-
adjust_load_path!
|
30
30
|
|
31
31
|
args = @argv.dup
|
32
32
|
argv_test_files = select_file_args(args)
|
@@ -42,6 +42,10 @@ module Nicetest
|
|
42
42
|
filters << name
|
43
43
|
end
|
44
44
|
|
45
|
+
# Gross hack to allow for plugins to be loaded before we require the test files
|
46
|
+
Minitest.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
|
47
|
+
processed_args = Minitest.process_args(args)
|
48
|
+
|
45
49
|
required_files = argv_test_files.map do |pattern|
|
46
50
|
file_or_dir, filter = finder.filter_for(pattern)
|
47
51
|
filters << filter if filter && !cli_options.name
|
@@ -49,13 +53,29 @@ module Nicetest
|
|
49
53
|
end
|
50
54
|
|
51
55
|
@logger.fatal!("no test files found") if required_files.compact.empty?
|
52
|
-
|
56
|
+
|
57
|
+
if filters.any?
|
58
|
+
processed_args[:filter] = Regexp.union(*filters.map do |filter|
|
59
|
+
Regexp.new("^#{filter}$")
|
60
|
+
end)
|
61
|
+
processed_args[:args] = "#{processed_args[:args]} --name=/^#{processed_args[:filter].source}$/"
|
62
|
+
end
|
63
|
+
|
64
|
+
patch_minitest_process_args!(processed_args)
|
53
65
|
|
54
66
|
Minitest.run(args)
|
55
67
|
end
|
56
68
|
|
57
69
|
private
|
58
70
|
|
71
|
+
def patch_minitest_process_args!(preprocessed)
|
72
|
+
original_process_args = Minitest.method(:process_args)
|
73
|
+
Minitest.define_singleton_method(:process_args) do |_input_args|
|
74
|
+
Minitest.define_singleton_method(:process_args, original_process_args)
|
75
|
+
preprocessed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
59
79
|
def fetch_dep_loadpaths(gemspec, seen = {})
|
60
80
|
return [] if seen[gemspec.name]
|
61
81
|
|
@@ -87,6 +107,7 @@ module Nicetest
|
|
87
107
|
|
88
108
|
loadpaths = fetch_dep_loadpaths(Gem.loaded_specs["nicetest"]).map { |path| "-I#{path}" }
|
89
109
|
requires = ["-rnicetest"]
|
110
|
+
includes = ["-I#{dir}/test"]
|
90
111
|
args_with_removed_leading_path = @argv.map do |arg|
|
91
112
|
arg = arg.dup
|
92
113
|
arg.delete_prefix!(dir)
|
@@ -102,6 +123,7 @@ module Nicetest
|
|
102
123
|
RbConfig.ruby,
|
103
124
|
*loadpaths,
|
104
125
|
*requires,
|
126
|
+
*includes,
|
105
127
|
"-e",
|
106
128
|
"exit(Nicetest::Cli.new(ARGV).run_tests)",
|
107
129
|
"--",
|
@@ -123,7 +145,7 @@ module Nicetest
|
|
123
145
|
|
124
146
|
def select_file_args(args)
|
125
147
|
args = args.dup
|
126
|
-
Minitest.instance_variable_set(:@extensions, Set.new) # Avoid double-loading plugins
|
148
|
+
Minitest.instance_variable_set(:@extensions, Set.new(Minitest.extensions)) # Avoid double-loading plugins
|
127
149
|
Minitest.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
|
128
150
|
# this will remove all options from the args array
|
129
151
|
temporarily_disable_optparse_callbacks { Minitest.process_args(args) }
|
@@ -131,14 +153,17 @@ module Nicetest
|
|
131
153
|
end
|
132
154
|
|
133
155
|
def glob_test_files(dir)
|
134
|
-
Dir
|
156
|
+
Dir[
|
157
|
+
"#{dir}/**/test_*.rb",
|
158
|
+
"#{dir}/**/*_{test,spec}.rb",
|
159
|
+
]
|
135
160
|
end
|
136
161
|
|
137
162
|
def require_path_or_dir(path_or_dir)
|
138
163
|
if path_or_dir.end_with?(".rb")
|
139
164
|
[try_require(path_or_dir)]
|
140
165
|
else
|
141
|
-
|
166
|
+
glob_test_files(path_or_dir).map do |f|
|
142
167
|
try_require(f)
|
143
168
|
end
|
144
169
|
end
|
@@ -159,7 +184,8 @@ module Nicetest
|
|
159
184
|
end
|
160
185
|
|
161
186
|
def adjust_load_path!
|
162
|
-
$LOAD_PATH.unshift(File.expand_path("test"))
|
187
|
+
$LOAD_PATH.unshift(File.expand_path("test")) unless @adjusted
|
188
|
+
@adjusted = true
|
163
189
|
end
|
164
190
|
|
165
191
|
def temporarily_disable_optparse_callbacks(&blk)
|
@@ -190,9 +216,8 @@ module Nicetest
|
|
190
216
|
options[:cd] = dir
|
191
217
|
end
|
192
218
|
|
193
|
-
opts.on("--
|
194
|
-
|
195
|
-
exit
|
219
|
+
opts.on("-n", "--name=PATTERN", "Filter test names on pattern") do |pattern|
|
220
|
+
options[:name] = pattern
|
196
221
|
end
|
197
222
|
end
|
198
223
|
|
data/lib/nicetest/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ker-Seymer
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
Lvd35BNvZkhFzs9xfykhurpkT2TiP2F3ZFn9dwLXMFe41pwrtEYLIWhYi8mUG4Ek
|
30
30
|
6aR8M/tqIpChVV39
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2024-
|
32
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: minitest
|
metadata.gz.sig
CHANGED
Binary file
|