minitest-line 0.5.0 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/minitest/line/describe_track.rb +13 -0
- data/lib/minitest/line_plugin.rb +76 -18
- metadata +14 -19
- data/test/test_line.rb +0 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f5682e0e61c883aee95ae4538f2351ec4c17791
|
4
|
+
data.tar.gz: 9c5ef7ac3bd9cfb7eee5005dea2a16d71366ada5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1e9d3c361b462e48be4eed806f723f0d4cfb8ee4ff2d32b0ab782090f4cf046d69037a3d41e52416659a461bbbdb754eaf739c8d3072453fc39a2867f1d025b
|
7
|
+
data.tar.gz: 8d6a52655b8aa605831a0f2a7f4fb461a35a4e4ce45524f0033726b404812d2ade8eefc26c8c565f0150b45dcad1f2b105b82459b64da2a16449c25aa95af8bd
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Minitest
|
2
|
+
module Line
|
3
|
+
module DescribeTrack
|
4
|
+
def describe(*args, &block)
|
5
|
+
klass = super
|
6
|
+
klass.instance_variable_set(:@minitest_line_caller, caller(0..5))
|
7
|
+
klass
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Object.send(:include, Minitest::Line::DescribeTrack)
|
data/lib/minitest/line_plugin.rb
CHANGED
@@ -1,4 +1,41 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module Minitest
|
4
|
+
module Line
|
5
|
+
class << self
|
6
|
+
def tests_with_lines
|
7
|
+
target_file = $0
|
8
|
+
methods_with_lines(target_file).concat describes_with_lines(target_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def methods_with_lines(target_file)
|
14
|
+
runnables.flat_map do |runnable|
|
15
|
+
rname = runnable.name
|
16
|
+
runnable.runnable_methods.map do |name|
|
17
|
+
file, line = runnable.instance_method(name).source_location
|
18
|
+
next unless file == target_file
|
19
|
+
test_name = (rname ? "#{rname}##{name}" : name)
|
20
|
+
[test_name, line]
|
21
|
+
end
|
22
|
+
end.uniq.compact
|
23
|
+
end
|
24
|
+
|
25
|
+
def describes_with_lines(target_file)
|
26
|
+
runnables.map do |runnable|
|
27
|
+
next unless caller = runnable.instance_variable_defined?(:@minitest_line_caller) && runnable.instance_variable_get(:@minitest_line_caller)
|
28
|
+
next unless line = caller.detect { |l| l.include?(target_file) }
|
29
|
+
["/#{Regexp.escape(runnable.name)}/", line[/:(\d+):in/, 1].to_i]
|
30
|
+
end.compact
|
31
|
+
end
|
32
|
+
|
33
|
+
def runnables
|
34
|
+
Minitest::Runnable.runnables
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
2
39
|
def self.plugin_line_options(opts, options)
|
3
40
|
opts.on '-l', '--line N', Integer, "Run test at line number" do |lineno|
|
4
41
|
options[:line] = lineno
|
@@ -6,31 +43,52 @@ module Minitest
|
|
6
43
|
end
|
7
44
|
|
8
45
|
def self.plugin_line_init(options)
|
9
|
-
|
46
|
+
unless exp_line = options[:line]
|
47
|
+
reporter.reporters << LineReporter.new
|
48
|
+
return
|
49
|
+
end
|
10
50
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end.uniq
|
51
|
+
tests = Minitest::Line.tests_with_lines
|
52
|
+
|
53
|
+
filter, _ = tests.sort_by { |n, l| -l }.detect { |n, l| exp_line >= l }
|
16
54
|
|
17
|
-
|
18
|
-
tests = {}
|
55
|
+
raise "Could not find test method before line #{exp_line}" unless filter
|
19
56
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
57
|
+
options[:filter] = filter
|
58
|
+
end
|
59
|
+
|
60
|
+
class LineReporter < Reporter
|
61
|
+
def initialize(*)
|
62
|
+
super
|
63
|
+
@failures = []
|
25
64
|
end
|
26
65
|
|
27
|
-
|
28
|
-
|
66
|
+
def record(result)
|
67
|
+
if !result.skipped? && !result.passed?
|
68
|
+
@failures << result
|
69
|
+
end
|
29
70
|
end
|
30
71
|
|
31
|
-
|
72
|
+
def report
|
73
|
+
return unless @failures.any?
|
74
|
+
io.puts
|
75
|
+
io.puts "Focus on failing tests:"
|
76
|
+
pwd = Pathname.new(Dir.pwd)
|
77
|
+
@failures.each do |res|
|
78
|
+
result = (res.respond_to?(:source_location) ? res : res.method(res.name))
|
79
|
+
file, line = result.source_location
|
32
80
|
|
33
|
-
|
81
|
+
if file
|
82
|
+
file = Pathname.new(file)
|
83
|
+
file = file.relative_path_from(pwd) if file.absolute?
|
84
|
+
output = "ruby #{file} -l #{line}"
|
85
|
+
output = "\e[31m#{output}\e[0m" if $stdout.tty?
|
86
|
+
io.puts output
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
34
90
|
end
|
35
|
-
end
|
36
91
|
|
92
|
+
def self.plugin_line_inject_reporter
|
93
|
+
end
|
94
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Magnus Holm
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '5.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '5.0'
|
30
27
|
description: Focused tests for Minitest
|
@@ -33,32 +30,30 @@ executables: []
|
|
33
30
|
extensions: []
|
34
31
|
extra_rdoc_files: []
|
35
32
|
files:
|
36
|
-
-
|
33
|
+
- lib/minitest/line/describe_track.rb
|
37
34
|
- lib/minitest/line_plugin.rb
|
38
35
|
homepage: https://github.com/judofyr/minitest-line
|
39
|
-
licenses:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
40
39
|
post_install_message:
|
41
40
|
rdoc_options: []
|
42
41
|
require_paths:
|
43
42
|
- lib
|
44
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - ">="
|
48
46
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
47
|
+
version: 2.0.0
|
50
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
49
|
requirements:
|
53
|
-
- -
|
50
|
+
- - ">="
|
54
51
|
- !ruby/object:Gem::Version
|
55
52
|
version: '0'
|
56
53
|
requirements: []
|
57
54
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.6.11
|
59
56
|
signing_key:
|
60
|
-
specification_version:
|
57
|
+
specification_version: 4
|
61
58
|
summary: Focused tests for Minitest
|
62
|
-
test_files:
|
63
|
-
- test/test_line.rb
|
64
|
-
has_rdoc:
|
59
|
+
test_files: []
|
data/test/test_line.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
require 'minitest'
|
5
|
-
require 'minitest/autorun'
|
6
|
-
require 'minitest/mock'
|
7
|
-
|
8
|
-
class LineExample < Minitest::Test
|
9
|
-
def test_hello
|
10
|
-
p :hello
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_world
|
14
|
-
p :world
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
Minitest::Runnable.runnables.delete(LineExample)
|
19
|
-
|
20
|
-
class TestLine < Minitest::Test
|
21
|
-
def run_class(klass, args = [])
|
22
|
-
Minitest::Runnable.stub :runnables, [klass] do
|
23
|
-
$stdout = io = StringIO.new
|
24
|
-
Minitest.run(args)
|
25
|
-
$stdout = STDOUT
|
26
|
-
io.string
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_line
|
31
|
-
(9..12).each do |line|
|
32
|
-
output = run_class LineExample, ['--line', line.to_s]
|
33
|
-
assert_match /1 runs/, output
|
34
|
-
assert_match /:hello/, output
|
35
|
-
refute_match /:world/, output
|
36
|
-
end
|
37
|
-
|
38
|
-
(13..45).each do |line|
|
39
|
-
output = run_class LineExample, ['--line', line.to_s]
|
40
|
-
assert_match /1 runs/, output
|
41
|
-
assert_match /:world/, output
|
42
|
-
refute_match /:hello/, output
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_before
|
47
|
-
assert_raises(RuntimeError) do
|
48
|
-
run_class LineExample, ['--line', '8']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|