Class: RSpec::Core::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/trunk_spec_helper.rb

Overview

Example is the class that represents a test case

Defined Under Namespace

Classes: Procsy

Instance Method Summary collapse

Instance Method Details

#assign_generated_descriptionObject



72
73
74
75
# File 'lib/trunk_spec_helper.rb', line 72

def assign_generated_description
  [:is_description_generated] = description_generated?
  assign_generated_description_core
end

#assign_generated_description_coreObject



44
# File 'lib/trunk_spec_helper.rb', line 44

alias assign_generated_description_core assign_generated_description

#description_generated?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/trunk_spec_helper.rb', line 77

def description_generated?
  return [:is_description_generated] unless [:is_description_generated].nil?

  description == location_description
end

#generate_trunk_idObject



83
84
85
# File 'lib/trunk_spec_helper.rb', line 83

def generate_trunk_id
  return "trunk:#{id}-#{location}" if description_generated?
end

#set_exception(exception) ⇒ Object

RSpec uses the existance of an exception to determine if the test failed We need to override this to allow us to capture the exception and then decide if we want to fail the test or not trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Naming/AccessorMethodName)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/trunk_spec_helper.rb', line 49

def set_exception(exception)
  return set_exception_core(exception) if [:pending]
  return set_exception_core(exception) if trunk_disabled
  return set_exception_core(exception) if [:retry_attempts]&.positive?

  id = generate_trunk_id
  name = full_description
  parent_name = example_group.[:description]
  parent_name = parent_name.empty? ? 'rspec' : parent_name
  file = escape([:file_path])
  classname = file.sub(%r{\.[^/.]+\Z}, '').gsub('/', '.').gsub(/\A\.+|\.+\Z/, '')
  puts "Test failed, checking if it can be quarantined: `#{location}`".yellow
  if $test_report.is_quarantined(id, name, parent_name, classname, file)
    # monitor the override in the metadata
    [:quarantined_exception] = exception
    puts "Test is quarantined, overriding exception: #{exception}".green
    nil
  else
    puts 'Test is not quarantined, continuing'.red
    set_exception_core(exception)
  end
end

#set_exception_coreObject

keep the original method around so we can call it



43
# File 'lib/trunk_spec_helper.rb', line 43

alias set_exception_core set_exception