minitest-heat 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,12 +74,16 @@ module Minitest
74
74
 
75
75
  # Show the marker
76
76
  output.marker(issue.type)
77
- rescue => e
77
+ rescue StandardError => e
78
+ display_exception_guidance(e)
79
+ end
80
+
81
+ def display_exception_guidance(exception)
78
82
  output.newline
79
- puts "Sorry, but Minitest Heat encountered an exception recording an issue. Disabling Minitest Heat will get you back on track."
80
- puts "Please use the following exception details to submit an issue at https://github.com/garrettdimon/minitest-heat/issues"
81
- puts "#{e.message}:"
82
- e.backtrace.each do |line|
83
+ puts 'Sorry, but Minitest Heat encountered an exception recording an issue. Disabling Minitest Heat will get you back on track.'
84
+ puts 'Please use the following exception details to submit an issue at https://github.com/garrettdimon/minitest-heat/issues'
85
+ puts "#{exception.message}:"
86
+ exception.backtrace.each do |line|
83
87
  puts " #{line}"
84
88
  end
85
89
  output.newline
@@ -99,6 +103,9 @@ module Minitest
99
103
  # If there were issues, shows a short heat map summary of which files and lines were the most
100
104
  # common sources of issues
101
105
  output.heat_map(results)
106
+
107
+ output.newline
108
+ output.newline
102
109
  end
103
110
 
104
111
  # Did this run pass?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-heat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Dimon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-31 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -143,10 +143,11 @@ files:
143
143
  - bin/setup
144
144
  - lib/minitest/heat.rb
145
145
  - lib/minitest/heat/backtrace.rb
146
- - lib/minitest/heat/backtrace/line.rb
146
+ - lib/minitest/heat/backtrace/line_parser.rb
147
147
  - lib/minitest/heat/hit.rb
148
148
  - lib/minitest/heat/issue.rb
149
149
  - lib/minitest/heat/location.rb
150
+ - lib/minitest/heat/locations.rb
150
151
  - lib/minitest/heat/map.rb
151
152
  - lib/minitest/heat/output.rb
152
153
  - lib/minitest/heat/output/backtrace.rb
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  - !ruby/object:Gem::Version
189
190
  version: '0'
190
191
  requirements: []
191
- rubygems_version: 3.1.6
192
+ rubygems_version: 3.2.22
192
193
  signing_key:
193
194
  specification_version: 4
194
195
  summary: Presents test results in a visual manner to guide you to where to look first.
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Minitest
6
- module Heat
7
- class Backtrace
8
- # Represents a line from a backtrace to provide more convenient access to information about
9
- # the relevant file and line number for displaying in test results
10
- class Line
11
- attr_accessor :pathname, :number, :container
12
- alias line_number number
13
-
14
- # Creates an instance of a line number reference
15
- # @param pathname: [Pathname, String] the full pathname to the file
16
- # @param number: [Integer, String] the line number in question
17
- # @param container: nil [String] the containing method or block for the line of code
18
- #
19
- # @return [self]
20
- def initialize(pathname:, number:, container: nil)
21
- @pathname = Pathname(pathname)
22
- @number = number.to_i
23
- @container = container.to_s
24
- end
25
-
26
- # Parses a line from a backtrace in order to convert it to usable components
27
- def self.parse_backtrace(raw_text)
28
- raw_pathname, raw_line_number, raw_container = raw_text.split(':')
29
- raw_container = raw_container.delete_prefix('in `').delete_suffix("'")
30
-
31
- new(pathname: raw_pathname, number: raw_line_number, container: raw_container)
32
- end
33
-
34
- # Generates a formatted string describing the line of code similar to the original backtrace
35
- #
36
- # @return [String] a consistently-formatted, human-readable string about the line of code
37
- def to_s
38
- "#{location} in `#{container}`"
39
- end
40
-
41
- # A safe interface to getting a string representing the path portion of the file
42
- #
43
- # @return [String] either the path/directory portion of the file name or '(Unrecognized File)'
44
- # if the offending file can't be found for some reason
45
- def path
46
- pathname.exist? ? pathname.dirname : UNRECOGNIZED
47
- end
48
-
49
- # A safe interface for getting a string representing the filename portion of the file
50
- #
51
- # @return [String] either the filename portion of the file or '(Unrecognized File)'
52
- # if the offending file can't be found for some reason
53
- def file
54
- pathname.exist? ? pathname.basename : UNRECOGNIZED
55
- end
56
-
57
- # A safe interface to getting the last modified time for the file in question
58
- #
59
- # @return [Time] the timestamp for when the file in question was last modified or `Time.at(0)`
60
- # if the offending file can't be found for some reason
61
- def mtime
62
- pathname.exist? ? pathname.mtime : UNKNOWN_MODIFICATION_TIME
63
- end
64
-
65
- # A safe interface to getting the number of seconds since the file was modified
66
- #
67
- # @return [Integer] the number of seconds since the file was modified or `-1` if the offending
68
- # file can't be found for some reason
69
- def age_in_seconds
70
- pathname.exist? ? seconds_ago : UNKNOWN_MODIFICATION_SECONDS
71
- end
72
-
73
- # A convenient method for getting the full location identifier using the full pathname and
74
- # line number separated by a `:`
75
- #
76
- # @return [String] the full pathname and line number
77
- def location
78
- "#{pathname}:#{number}"
79
- end
80
-
81
- # A convenient method for getting the short location with `Dir.pwd` removed
82
- #
83
- # @return [String] the relative pathname and line number
84
- def short_location
85
- "#{file}:#{number}"
86
- end
87
-
88
- # A convenient method for getting the line of source code for the offending line number
89
- #
90
- # @return [String] the source code for the file/line number combination
91
- def source_code(max_line_count: 1)
92
- Minitest::Heat::Source.new(
93
- pathname.to_s,
94
- line_number: line_number,
95
- max_line_count: max_line_count
96
- )
97
- end
98
-
99
- # Determines if a given file follows the standard approaching to naming test files.
100
- #
101
- # @return [Boolean] true if the file name starts with `test_` or ends with `_test.rb`
102
- def test_file?
103
- file.to_s.start_with?('test_') || file.to_s.end_with?('_test.rb')
104
- end
105
-
106
- private
107
-
108
- UNRECOGNIZED = '(Unrecognized File)'
109
- UNKNOWN_MODIFICATION_TIME = Time.at(0)
110
- UNKNOWN_MODIFICATION_SECONDS = -1
111
-
112
- def seconds_ago
113
- (Time.now - mtime).to_i
114
- end
115
- end
116
- end
117
- end
118
- end