Top Level Namespace

Defined Under Namespace

Modules: RSpec Classes: String, TrunkAnalyticsListener

Instance Method Summary collapse

Instance Method Details

#escape(str) ⇒ Object



56
57
58
# File 'lib/trunk_spec_helper.rb', line 56

def escape(str)
  str.dump[1..-2]
end

#format_exception_backtrace(exception) ⇒ Object

trunk-ignore(rubocop/Metrics/MethodLength)



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/trunk_spec_helper.rb', line 201

def format_exception_backtrace(exception)
  case exception
  when RSpec::Core::MultipleExceptionError
    # Collect backtraces from all nested exceptions
    backtraces = exception.all_exceptions.map do |e|
      if e.backtrace && !e.backtrace.empty?
        "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
      else
        "#{e.class}: #{e.message}"
      end
    end
    backtraces.join("\n\n")
  else
    exception.backtrace&.join("\n") || ''
  end
end

#format_exception_message(exception) ⇒ Object



189
190
191
192
193
194
195
196
197
198
# File 'lib/trunk_spec_helper.rb', line 189

def format_exception_message(exception)
  case exception
  when RSpec::Core::MultipleExceptionError
    # MultipleExceptionError contains multiple exceptions in @exceptions array
    messages = exception.all_exceptions.map { |e| "#{e.class}: #{e.message}" }
    "#{exception.class}: #{messages.join(' | ')}"
  else
    exception.to_s
  end
end

#knapsack_detector_command?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/trunk_spec_helper.rb', line 67

def knapsack_detector_command?
  command_line = "#{$PROGRAM_NAME} #{ARGV.join(' ')}".strip
  command_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

Returns:

  • (Boolean)


63
64
65
# File 'lib/trunk_spec_helper.rb', line 63

def knapsack_detector_mode?
  knapsack_detector_command?
end

#trunk_disabledObject



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

def trunk_disabled
  knapsack_detector_mode? || ENV['DISABLE_RSPEC_TRUNK_FLAKY_TESTS'] == 'true' ||
    ENV['TRUNK_ORG_URL_SLUG'].nil? || ENV['TRUNK_API_TOKEN'].nil?
end