Defer to RSpec's own ExceptionPresenter so the failure_message field matches what users see in their RSpec console output (Failure/Error: , the exception class and message, and any "Caused by:" chain).
Knapsack example detector instantiates all test cases in order to determine how to shard them These instantiations should not generate test bundles, so we disable the gem when running under knapsack_pro:rspec_test_example_detector.
# File 'lib/trunk_spec_helper.rb', line 265defexception_backtrace_lines(exception,example)presenter=RSpec::Core::Formatters::ExceptionPresenter.new(exception,example)Array(presenter.formatted_backtrace)rescueStandardErrorArray(exception.backtrace)end
# File 'lib/trunk_spec_helper.rb', line 240defformat_exception_backtrace(exception,example)return''unlessexceptionlines=exception_backtrace_lines(exception,example)cause=exception.causedepth=0whilecause&&depth<10lines<<''lines<<"Caused by: #{cause.class}: #{cause.message}"lines.concat(exception_backtrace_lines(cause,example))cause=cause.causedepth+=1endresult=lines.join("\n")# The exception presenter may choke on MultipleExceptionError, such as errors in before
# and after hooks, so we fall back to the legacy formatter
returnlegacy_format_exception_backtrace(exception)ifresult.strip.empty?strip_ansi_codes(result)rescueStandardErrorlegacy_format_exception_backtrace(exception)end
Defer to RSpec's own ExceptionPresenter so the failure_message field matches
what users see in their RSpec console output (Failure/Error: ,
the exception class and message, and any "Caused by:" chain).
230
231
232
233
234
235
236
237
# File 'lib/trunk_spec_helper.rb', line 230defformat_exception_message(exception,example)return''unlessexceptionpresenter=RSpec::Core::Formatters::ExceptionPresenter.new(exception,example)strip_ansi_codes(presenter.fully_formatted(nil,PlainColorizer))rescueStandardErrorlegacy_format_exception_message(exception)end
#knapsack_detector_command? ⇒ Boolean
Returns:
(Boolean)
79
80
81
82
83
# File 'lib/trunk_spec_helper.rb', line 79defknapsack_detector_command?command_line="#{$PROGRAM_NAME}#{ARGV.join('')}".stripcommand_line.include?('knapsack_pro:rspec_test_example_detector')||command_line.include?('knapsack_pro:queue:rspec:initialize')end
#knapsack_detector_mode? ⇒ Boolean
Knapsack example detector instantiates all test cases in order to determine how to shard them
These instantiations should not generate test bundles, so we
disable the gem when running under knapsack_pro:rspec_test_example_detector
# File 'lib/trunk_spec_helper.rb', line 272deflegacy_format_exception_message(exception)caseexceptionwhenRSpec::Core::MultipleExceptionErrormessages=exception.all_exceptions.map{|e|"#{e.class}: #{e.message}"}strip_ansi_codes("#{exception.class}: #{messages.join(' | ')}")elsestrip_ansi_codes(exception.to_s)endend
#quarantine_query_failure_exit? ⇒ Boolean
Returns:
(Boolean)
90
91
92
# File 'lib/trunk_spec_helper.rb', line 90defquarantine_query_failure_exit?ENV['TRUNK_QUARANTINE_QUERY_FAILURE_EXIT']=='true'end
#strip_ansi_codes(text) ⇒ Object
68
69
70
# File 'lib/trunk_spec_helper.rb', line 68defstrip_ansi_codes(text)text.to_s.gsub(ANSI_ESCAPE_PATTERN,'')end
#trunk_disabled ⇒ Object
85
86
87
88
# File 'lib/trunk_spec_helper.rb', line 85deftrunk_disabledknapsack_detector_mode?||ENV['DISABLE_RSPEC_TRUNK_FLAKY_TESTS']=='true'||ENV['TRUNK_ORG_URL_SLUG'].nil?||ENV['TRUNK_API_TOKEN'].nil?end