class Petitest::Texts::RaisedCodeText

Attributes

test[R]

@return [Petitest::Test]

Public Class Methods

new(test:) click to toggle source

@param test [Petitest::Test]

# File lib/petitest/texts/raised_code_text.rb, line 10
def initialize(test:)
  @test = test
end

Public Instance Methods

to_s() click to toggle source

@note Override

# File lib/petitest/texts/raised_code_text.rb, line 15
def to_s
  if content = caller_file_content
    content.lines[caller_line_number - 1].strip
  else
    ""
  end
end

Private Instance Methods

caller_file_content() click to toggle source

@return [String, nil]

# File lib/petitest/texts/raised_code_text.rb, line 26
def caller_file_content
  if caller_path && ::FileTest.file?(caller_path)
    ::File.read(caller_path)
  end
end
caller_line_number() click to toggle source

@return [String, nil]

# File lib/petitest/texts/raised_code_text.rb, line 33
def caller_line_number
  if caller_segments[1]
    caller_segments[1].to_i
  end
end
caller_path() click to toggle source

@return [String, nil]

# File lib/petitest/texts/raised_code_text.rb, line 40
def caller_path
  caller_segments[0]
end
caller_segments() click to toggle source

@return [Array<String>]

# File lib/petitest/texts/raised_code_text.rb, line 45
def caller_segments
  @caller_segments ||= begin
    if test.runner.filtered_backtrace[0]
      test.runner.filtered_backtrace[0].split(":", 3)
    else
      []
    end
  end
end