enhanced_errors 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,6 +85,8 @@ class EnhancedErrors
85
85
 
86
86
  DEFAULT_SKIP_LIST = (RAILS_SKIP_LIST + RSPEC_SKIP_LIST + MINITEST_SKIP_LIST)
87
87
 
88
+ RSPEC_HANDLER_NAMES = ['RSpec::Expectations::PositiveExpectationHandler', 'RSpec::Expectations::NegativeExpectationHandler']
89
+
88
90
  @enabled = false
89
91
  @max_length = nil
90
92
  @capture_rescue = nil
@@ -149,6 +151,8 @@ class EnhancedErrors
149
151
 
150
152
  def increment_capture_events_count
151
153
  mutex.synchronize do
154
+ @capture_events_count ||= 0
155
+ @max_capture_events ||= -1
152
156
  @capture_events_count += 1
153
157
  # Check if we've hit the limit
154
158
  if @max_capture_events > 0 && @capture_events_count >= @max_capture_events
@@ -184,6 +188,19 @@ class EnhancedErrors
184
188
  end
185
189
  end
186
190
 
191
+ def override_rspec_message(example, binding_or_bindings)
192
+ exception_obj = example.exception
193
+ case exception_obj
194
+ when nil
195
+ return nil
196
+ when RSpec::Core::MultipleExceptionError
197
+ override_exception_message(exception_obj.all_exceptions.first, binding_or_bindings)
198
+ else
199
+ override_exception_message(exception_obj, binding_or_bindings)
200
+ end
201
+
202
+ end
203
+
187
204
  def override_exception_message(exception, binding_or_bindings)
188
205
  return nil unless exception
189
206
  rspec_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
@@ -312,6 +329,19 @@ class EnhancedErrors
312
329
  end
313
330
  end
314
331
 
332
+ def class_to_string(klass)
333
+ return '' if klass.nil?
334
+ if klass.singleton_class?
335
+ klass.to_s.match(/#<Class:(.*?)>/)[1]
336
+ else
337
+ klass.to_s
338
+ end
339
+ end
340
+
341
+ def is_rspec_example?(tracepoint)
342
+ tracepoint.method_id.nil? && !(tracepoint.path.include?('rspec')) && tracepoint.path.end_with?('_spec.rb')
343
+ end
344
+
315
345
  def start_rspec_binding_capture
316
346
  mutex.synchronize do
317
347
  @rspec_example_binding = nil
@@ -320,18 +350,27 @@ class EnhancedErrors
320
350
  @enabled = true if @enabled.nil?
321
351
 
322
352
  @rspec_tracepoint = TracePoint.new(:raise, :b_return) do |tp|
323
- # This trickery is to help us identify the anonymous block return we want to grab
353
+ # puts "name #{tp.raised_exception.class.name rescue ''} method:#{tp.method_id} tp.binding:#{tp.binding.local_variables rescue ''}"
354
+ # puts "event: #{tp.event} defined_class#{class_to_string(tp.defined_class)} #{tp.path}:#{tp.lineno} #{tp.callee_id} "
355
+ # This trickery below is to help us identify the anonymous block return we want to grab
356
+ # Very kluge-y and edge cases have grown it, but it works
324
357
  if tp.event == :b_return
325
- next unless @capture_next_binding && @rspec_example_binding.nil?
326
- if @capture_next_binding && tp.method_id.nil? && !(tp.path.include?('rspec')) && tp.path.end_with?('_spec.rb')
327
- if determine_object_name(tp) =~ RSPEC_EXAMPLE_REGEXP
328
- increment_capture_events_count
329
- @rspec_example_binding = tp.binding
330
- end
358
+ if RSPEC_HANDLER_NAMES.include?(class_to_string(tp.defined_class))
359
+ @capture_next_binding = :next
360
+ next
361
+ end
362
+ next unless @capture_next_binding
363
+
364
+ if @capture_next_binding == :next || @capture_next_binding == :next_matching && is_rspec_example?(tp)
365
+ increment_capture_events_count
366
+ @capture_next_binding = false
367
+ @rspec_example_binding = tp.binding
331
368
  end
332
369
  elsif tp.event == :raise
333
- if tp.raised_exception.class.name == 'RSpec::Expectations::ExpectationNotMetError'
334
- @capture_next_binding ||= true
370
+ class_name = tp.raised_exception.class.name
371
+ case class_name
372
+ when 'RSpec::Expectations::ExpectationNotMetError'
373
+ @capture_next_binding = :next_matching
335
374
  else
336
375
  handle_tracepoint_event(tp)
337
376
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enhanced_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-15 00:00:00.000000000 Z
11
+ date: 2024-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -90,6 +90,7 @@ files:
90
90
  - doc/Enhanced/Integrations/RSpecErrorFailureMessage.html
91
91
  - doc/EnhancedErrors.html
92
92
  - doc/Exception.html
93
+ - doc/Minitest.html
93
94
  - doc/_index.html
94
95
  - doc/class_list.html
95
96
  - doc/css/common.css