Class: TestTrace

Inherits:
Object show all
Includes:
TmcHelpers
Defined in:
lib/test_case/test_trace.rb

Direct Known Subclasses

TestError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TmcHelpers

#aws_config, #aws_create_s3_bucket, #aws_delete_s3, #aws_delete_s3_bucket, #aws_read_s3, #aws_upload_s3, #aws_write_s3, #get_clean_ocr_text, #get_readable_size, #get_readable_time, #get_string_similarity, #get_substring_similarity, #is_rating?, #is_year?, #jsonify, #pick_random, #rubify, #send_webex_alert, #to_camel_case, #to_pascal_case, #to_snake_case, #twb_case_exists?, #twb_get_case_instance_id, #twb_get_suite_instance_id, #twb_post_screenshot, #twb_post_screenshot!, #twb_post_suite, #twb_post_testcase, #twb_post_teststep, #twb_post_teststep!, #twb_prep_s3_screenshot, #twb_suite_exists?, #until_condition, #until_equals, #until_includes, #until_not_empty, #until_not_equals, #until_not_includes, #until_not_nil, #until_same, #web_delete, #web_get, #web_post, #web_put

Methods included from HttpHelper

#web_request

Methods included from CsvHelper

#csv_parse, #csv_read

Methods included from SshHelper

#ssh_to

Methods included from EmailHelper

#send_email, #send_email_setup

Methods included from SnmpHelper

#snmp_get, #snmp_set

Constructor Details

#initialize(test_case, backtrace, exclude_files: []) ⇒ TestTrace

Public: Initializes a new test trace.

test_case - TestCase instance in which the trace occurred. backtrace - Array containing call stack. exclude_files - Array of file names to exclude from trace (default: []).

Returns new TestTrace instance.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/test_case/test_trace.rb', line 16

def initialize(test_case, backtrace, exclude_files: [])
  exclude_files += ['delegate.rb']
  exclude_files.map! {|f| File.join('', f)}
  path = backtrace.find do |t|
    if t.include?('/ruby/gems/')
      false
    elsif exclude_files.any? {|f| t.include?(f)}
      false
    else
      true
    end
  end || backtrace.first
  @path = path.split(/[\\\/]/).last
  parts = path.split(/\:(?!\/)/)
  type_match = parts[0].match(/[\\\/](lib|test_cases)[\\\/]/)
  unless type_match.nil?
    @file = parts[0].split(type_match.to_s)[1]
    if type_match[1] == 'lib'
      rel_parts = parts[0].split(/[\\\/]/)
      if rel_parts.include?('prereqs')
        @type = 'prereq'
        @prereq_type = rel_parts.last.match(/prereqs_for_(.*)\./)[1]
      elsif rel_parts.include?('helpers')
        @type = 'helper'
      else
        @type = 'method'
      end
    elsif type_match[1] == 'test_cases'
      @type = 'script'
    end
  end
  @line = parts[1].to_i
  @method = parts[2].match(/`([^']+)'/)[1].to_s.split(' ').last
  # best effort to get line in method
  @line_in_method = nil
  cls = Object.const_get(to_pascal_case(File.split(@file).last.split('.').first)) rescue nil  # try to get class from source file
  if cls.nil?
    # try getting the method from the test case instance
    meth = test_case.method(@method.to_sym) rescue nil
  else
    # try getting the method from the class in the source file
    meth = cls.instance_method(@method.to_sym) rescue nil
  end
  if !meth.nil? && !meth.source_location.nil?
    # we found the method
    source_line = meth.source_location[1]
    @line_in_method = line - source_line
  end
  @hash = {
    file: @file,
    line: @line,
    method: @method,
    line_in_method: @line_in_method,
    type: @type,
    prereq_type: @prereq_type
  }
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/test_case/test_trace.rb', line 7

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



7
8
9
# File 'lib/test_case/test_trace.rb', line 7

def line
  @line
end

#line_in_methodObject (readonly)

Returns the value of attribute line_in_method.



7
8
9
# File 'lib/test_case/test_trace.rb', line 7

def line_in_method
  @line_in_method
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/test_case/test_trace.rb', line 7

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/test_case/test_trace.rb', line 7

def path
  @path
end

Instance Method Details

#to_hObject

Public: Gets hash representation of trace.

Returns Hash of trace attributes.



77
78
79
# File 'lib/test_case/test_trace.rb', line 77

def to_h
  @hash
end