Module: OnlyofficeTestrailWrapper::RspecHelper

Defined in:
lib/onlyoffice_testrail_wrapper/helpers/rspec_helper.rb

Overview

Methods to some rspec methods

Class Method Summary collapse

Class Method Details

.find_failed_line(example) ⇒ String

This method is based on github.com/rspec/rspec-core/blob/v3.3.0/lib/rspec/core/formatters/exception_presenter.rb#L130 It extracted exact line of code from failed exception

Parameters:

Returns:

  • (String)

    line value



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/onlyoffice_testrail_wrapper/helpers/rspec_helper.rb', line 13

def self.find_failed_line(example)
  example_path = example.[:absolute_file_path].downcase
  dirty_line = example.exception.backtrace.find do |line|
    next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])

    File.expand_path(line_path).casecmp(example_path).zero?
  end
  line_number = dirty_line[/:\d*:/].delete(':').to_i
  OnlyofficeFileHelper::FileHelper.read_array_from_file(example.[:absolute_file_path])[line_number - 1]
rescue StandardError => e
  "Cannot find failed line because of exception: #{e}"
end