Class: TLDR::Test

Inherits:
Struct
  • Object
show all
Defined in:
lib/tldr/value/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Test

Returns a new instance of Test.



5
6
7
8
9
# File 'lib/tldr/value/test.rb', line 5

def initialize(*args)
  super
  @file, @line = SorbetCompatibility.unwrap_method(test_class.instance_method(method_name)).source_location
  @location = Location.new(file, line)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/tldr/value/test.rb', line 3

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



3
4
5
# File 'lib/tldr/value/test.rb', line 3

def line
  @line
end

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/tldr/value/test.rb', line 3

def location
  @location
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



2
3
4
# File 'lib/tldr/value/test.rb', line 2

def method_name
  @method_name
end

#test_classObject

Returns the value of attribute test_class

Returns:

  • (Object)

    the current value of test_class



2
3
4
# File 'lib/tldr/value/test.rb', line 2

def test_class
  @test_class
end

Instance Method Details

#covers_line?(l) ⇒ Boolean

Test exact match starting line condition first to save us a potential re-parsing to look up end_line

Returns:

  • (Boolean)


20
21
22
# File 'lib/tldr/value/test.rb', line 20

def covers_line? l
  line == l || (l >= line && l <= end_line)
end

#end_lineObject

Memoizing at call time, because re-parsing isn’t free and isn’t usually necessary



12
13
14
15
16
17
# File 'lib/tldr/value/test.rb', line 12

def end_line
  @end_line ||= begin
    test_method = SorbetCompatibility.unwrap_method(test_class.instance_method(method_name))
    RubyVM::AbstractSyntaxTree.of(test_method).last_lineno
  end
end

#group?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tldr/value/test.rb', line 24

def group?
  false
end