Class: RSpec::Core::Example
- Inherits:
-
Object
- Object
- RSpec::Core::Example
- 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
- #assign_generated_description ⇒ Object
- #assign_generated_description_core ⇒ Object
- #description_generated? ⇒ Boolean
- #generate_trunk_id ⇒ Object
-
#handle_quarantine_check(exception) ⇒ Object
trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Metrics/CyclomaticComplexity).
-
#handle_quarantine_check_safely(exception) ⇒ Object
If the quarantine machinery itself blows up, the failure must stand.
- #pending_example_fixed?(exception) ⇒ Boolean
-
#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/Naming/AccessorMethodName).
-
#set_exception_core ⇒ Object
keep the original method around so we can call it.
Instance Method Details
#assign_generated_description ⇒ Object
172 173 174 175 |
# File 'lib/trunk_spec_helper.rb', line 172 def assign_generated_description [:is_description_generated] = description_generated? assign_generated_description_core end |
#assign_generated_description_core ⇒ Object
105 |
# File 'lib/trunk_spec_helper.rb', line 105 alias assign_generated_description_core assign_generated_description |
#description_generated? ⇒ Boolean
177 178 179 180 181 |
# File 'lib/trunk_spec_helper.rb', line 177 def description_generated? return [:is_description_generated] unless [:is_description_generated].nil? description == location_description end |
#generate_trunk_id ⇒ Object
183 184 185 |
# File 'lib/trunk_spec_helper.rb', line 183 def generate_trunk_id return "trunk:#{id}-#{location}" if description_generated? end |
#handle_quarantine_check(exception) ⇒ Object
trunk-ignore(rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength,rubocop/Metrics/CyclomaticComplexity)
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/trunk_spec_helper.rb', line 133 def handle_quarantine_check(exception) 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/, '') unless $failure_encountered_and_quarantining_disabled puts "Test failed, checking if it can be quarantined: `#{location}`".yellow end is_quarantined_result = $test_report.is_quarantined(id, name, parent_name, classname, file) if is_quarantined_result.quarantine_lookup_failed unless $failure_encountered_and_quarantine_lookup_failed puts 'Failed to check quarantining status, no failures will be quarantined'.yellow $failure_encountered_and_quarantine_lookup_failed = true end if quarantine_query_failure_exit? puts 'Quarantine lookup failed, exiting early'.red RSpec.world.wants_to_quit = true end set_exception_core(exception) elsif is_quarantined_result.quarantining_disabled_for_repo unless $failure_encountered_and_quarantining_disabled puts 'Quarantining is disabled for this repo, no failures will be quarantined'.yellow $failure_encountered_and_quarantining_disabled = true end set_exception_core(exception) elsif is_quarantined_result.test_is_quarantined # 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 |
#handle_quarantine_check_safely(exception) ⇒ Object
If the quarantine machinery itself blows up, the failure must stand.
120 121 122 123 124 125 |
# File 'lib/trunk_spec_helper.rb', line 120 def handle_quarantine_check_safely(exception) handle_quarantine_check(exception) rescue StandardError => e puts "Quarantine check errored (#{e.class}: #{e.}), treating test as not quarantined".yellow set_exception_core(exception) end |
#pending_example_fixed?(exception) ⇒ Boolean
127 128 129 130 |
# File 'lib/trunk_spec_helper.rb', line 127 def pending_example_fixed?(exception) defined?(RSpec::Core::Pending::PendingExampleFixedError) && exception.is_a?(RSpec::Core::Pending::PendingExampleFixedError) 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/Naming/AccessorMethodName)
110 111 112 113 114 115 116 117 |
# File 'lib/trunk_spec_helper.rb', line 110 def set_exception(exception) # Pending stays green, except a fixed pending example is a real failure. return set_exception_core(exception) if [:pending] && !pending_example_fixed?(exception) return set_exception_core(exception) if trunk_disabled return set_exception_core(exception) if [:retry_attempts]&.positive? handle_quarantine_check_safely(exception) end |
#set_exception_core ⇒ Object
keep the original method around so we can call it
104 |
# File 'lib/trunk_spec_helper.rb', line 104 alias set_exception_core set_exception |