Class: Minitest::BacktraceFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest.rb

Overview

The standard backtrace filter for minitest.

See Minitest.backtrace_filter=.

Constant Summary collapse

MT_RE =

:nodoc:

%r%lib/minitest|internal:warning%

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp = MT_RE) ⇒ BacktraceFilter

:nodoc:



1184
1185
1186
# File 'lib/minitest.rb', line 1184

def initialize regexp = MT_RE # :nodoc:
  self.regexp = regexp
end

Instance Attribute Details

#regexpObject

The regular expression to use to filter backtraces. Defaults to MT_RE.



1182
1183
1184
# File 'lib/minitest.rb', line 1182

def regexp
  @regexp
end

Instance Method Details

#filter(bt) ⇒ Object

Filter bt to something useful. Returns the whole thing if $DEBUG (ruby) or $MT_DEBUG (env).



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/minitest.rb', line 1192

def filter bt
  return ["No backtrace"] unless bt

  return bt.dup if $DEBUG || ENV["MT_DEBUG"]

  new_bt = bt.take_while { |line| !regexp.match? line.to_s }
  new_bt = bt.select     { |line| !regexp.match? line.to_s } if new_bt.empty?
  new_bt = bt.dup                                            if new_bt.empty?

  new_bt
end