Module: OnlyofficeTcmHelper::RspecHelper

Included in:
TcmHelper
Defined in:
lib/onlyoffice_tcm_helper/helpers/rspec_helper.rb

Overview

module with methods for parsing test results

Class Method Summary collapse

Class Method Details

.find_dirty_line(example) ⇒ String

Find dirty line in example

Parameters:

  • example (RSpec::Core::Example)

Returns:

  • (String)

    dirty line



24
25
26
27
28
29
30
31
# File 'lib/onlyoffice_tcm_helper/helpers/rspec_helper.rb', line 24

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

    File.expand_path(line_path).casecmp(example_path).zero?
  end
end

.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:

  • example (RSpec::Core::Example)

Returns:

  • (String)

    line value



13
14
15
16
17
18
19
# File 'lib/onlyoffice_tcm_helper/helpers/rspec_helper.rb', line 13

def self.find_failed_line(example)
  dirty_line = find_dirty_line(example)
  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