123456789_123456789_123456789_123456789_123456789_

Class: Minitest::PathExpander::TM

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Data
Instance Chain:
self, Data
Inherits: Data
  • Object
Defined in: lib/minitest/path_expander.rb

Overview

Simple TestMethod (abbr TM) Data object.

Class Method Summary

Instance Attribute Summary

  • #klass readonly

    Simple TestMethod (abbr TM) Data object.

  • #lines readonly

    Simple TestMethod (abbr TM) Data object.

  • #name readonly

    Simple TestMethod (abbr TM) Data object.

  • #path readonly

    Simple TestMethod (abbr TM) Data object.

Instance Method Summary

Constructor Details

.new(klass:, name:) ⇒ TM

[ GitHub ]

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

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

Class Method Details

.cache

[ GitHub ]

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

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

.source_for(method)

[ GitHub ]

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

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 Attribute Details

#klass (readonly)

Simple TestMethod (abbr TM) Data object.

[ GitHub ]

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

TM = Data.define :klass, :name, :path, :lines do
    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 (readonly)

Simple TestMethod (abbr TM) Data object.

[ GitHub ]

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

TM = Data.define :klass, :name, :path, :lines do
    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)

#name (readonly)

Simple TestMethod (abbr TM) Data object.

[ GitHub ]

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

TM = Data.define :klass, :name, :path, :lines do
    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)

#path (readonly)

Simple TestMethod (abbr TM) Data object.

[ GitHub ]

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

TM = Data.define :klass, :name, :path, :lines do
    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)

Instance Method Details

#include?(o) ⇒ Boolean

[ GitHub ]

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

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

#line_s

[ GitHub ]

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

def line_s = lines.begin

#to_s

[ GitHub ]

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

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