Class: Minitest::PathExpander::TM

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

Overview

Simple TestMethod (abbr TM) Data object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass:, name:) ⇒ TM

Returns a new instance of TM.



397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/minitest/path_expander.rb', line 397

def initialize klass:, name:
  method = klass.instance_method name
  path, line_s = method.source_location

  path = path.delete_prefix "#{Dir.pwd}/"

  line_e = line_s + TM.source_for(method).lines.size - 1

  lines = line_s..line_e

  super klass:, name:, path:, lines:
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



396
397
398
# File 'lib/minitest/path_expander.rb', line 396

def klass
  @klass
end

#linesObject (readonly)

Returns the value of attribute lines

Returns:

  • (Object)

    the current value of lines



396
397
398
# File 'lib/minitest/path_expander.rb', line 396

def lines
  @lines
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



396
397
398
# File 'lib/minitest/path_expander.rb', line 396

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



396
397
398
# File 'lib/minitest/path_expander.rb', line 396

def path
  @path
end

Class Method Details

.cacheObject



424
# File 'lib/minitest/path_expander.rb', line 424

def self.cache = @cache ||= {}

.source_for(method) ⇒ Object



410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/minitest/path_expander.rb', line 410

def self.source_for method
  path, line = method.source_location
  file = cache[path] ||= File.readlines(path)

  ruby = +""

  file[line-1..].each do |l|
    ruby << l
    return ruby if Prism.parse_success? ruby
  end

  nil
end

Instance Method Details

#include?(o) ⇒ Boolean

Returns:

  • (Boolean)


426
# File 'lib/minitest/path_expander.rb', line 426

def include?(o) = o.is_a?(Integer) ? lines.include?(o) : lines.overlap?(o)

#line_sObject



430
# File 'lib/minitest/path_expander.rb', line 430

def line_s = lines.begin

#to_sObject



428
# File 'lib/minitest/path_expander.rb', line 428

def to_s = "%s:%d-%d" % [path, lines.begin, lines.end]