minitest-line 0.6.2 → 0.6.3

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
  SHA1:
3
- metadata.gz: e5ce066391b220600b0c1866d5000050bd9aeaa9
4
- data.tar.gz: ac7e7ae85bbb0d820b6a4be83c0b7039ff56e284
3
+ metadata.gz: 6f044801efcc67afb2b576858ec11a4214e048b0
4
+ data.tar.gz: 06d87c3848f4d297a183b7de8196b0acdfd10921
5
5
  SHA512:
6
- metadata.gz: b58cd597e96cc4f0f1d40fdaab8e0007c178161987355ba212a985efd39750d3148b44ebe4536dd5de257f76f428ef80c679957668c365e499bfdcb24303a801
7
- data.tar.gz: b3bef54a0ae8f41e2efe1cfcdfe19d9deeccc0b8aaf7cc677f0c9cc64478cea00477b90b3a1032dea039710915656994938987173d701012da153ac724ca3c9c
6
+ metadata.gz: b84f0c75b45d2e31368e0c39b64c047be30937a4e2acdd88c7566f0a7eb0f075b79ef785a39fe55a16b108bf53ec2c8272d428ece2707908478b45ee2a476397
7
+ data.tar.gz: e4fe4e0a823e4e7fefe54b661adcc6d268edc106ce758ec6a37454cb41d0d17e53f133ffdb898a7b70fb84dc71a38699517fd89d4cc89924ce0a83398a6a2ad1
@@ -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)
@@ -1,6 +1,41 @@
1
1
  require 'pathname'
2
2
 
3
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_get(:@minitest_line_caller)
28
+ next unless line = caller.detect { |line| line.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
+
4
39
  def self.plugin_line_options(opts, options)
5
40
  opts.on '-l', '--line N', Integer, "Run test at line number" do |lineno|
6
41
  options[:line] = lineno
@@ -8,35 +43,18 @@ module Minitest
8
43
  end
9
44
 
10
45
  def self.plugin_line_init(options)
11
- exp_line = options[:line]
12
- if !exp_line
46
+ unless exp_line = options[:line]
13
47
  reporter.reporters << LineReporter.new
14
48
  return
15
49
  end
16
50
 
17
- methods = Runnable.runnables.flat_map do |runnable|
18
- runnable.runnable_methods.map do |name|
19
- [name, runnable.instance_method(name)]
20
- end
21
- end.uniq
22
-
23
- current_filename = nil
24
- tests = {}
51
+ tests = Minitest::Line.tests_with_lines
25
52
 
26
- methods.each do |name, meth|
27
- next unless loc = meth.source_location
28
- current_filename ||= loc[0]
29
- next unless current_filename == loc[0]
30
- tests[loc[1]] = name
31
- end
32
-
33
- _, main_test = tests.sort_by { |k, v| -k }.detect do |line, name|
34
- exp_line >= line
35
- end
53
+ filter, _ = tests.sort_by { |n, l| -l }.detect { |n, l| exp_line >= l }
36
54
 
37
- raise "Could not find test method after line #{exp_line}" unless main_test
55
+ raise "Could not find test method before line #{exp_line}" unless filter
38
56
 
39
- options[:filter] = main_test
57
+ options[:filter] = filter
40
58
  end
41
59
 
42
60
  class LineReporter < Reporter
@@ -62,7 +80,9 @@ module Minitest
62
80
  if file
63
81
  file = Pathname.new(file)
64
82
  file = file.relative_path_from(pwd) if file.absolute?
65
- io.puts "ruby #{file} -l #{line}"
83
+ output = "ruby #{file} -l #{line}"
84
+ output = "\e[31m#{output}\e[0m" if $stdout.tty?
85
+ io.puts output
66
86
  end
67
87
  end
68
88
  end
@@ -71,4 +91,3 @@ module Minitest
71
91
  def self.plugin_line_inject_reporter
72
92
  end
73
93
  end
74
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-line
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Holm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -30,6 +30,7 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - lib/minitest/line/describe_track.rb
33
34
  - lib/minitest/line_plugin.rb
34
35
  homepage: https://github.com/judofyr/minitest-line
35
36
  licenses: