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.
- checksums.yaml +4 -4
- data/.yardoc/checksums +4 -4
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/README.md +5 -1
- data/doc/Enhanced/Colors.html +24 -17
- data/doc/Enhanced.html +2 -6
- data/doc/EnhancedErrors.html +1764 -888
- data/doc/Exception.html +1 -1
- data/doc/Minitest.html +238 -0
- data/doc/_index.html +4 -21
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +74 -78
- data/doc/index.html +74 -78
- data/doc/method_list.html +125 -13
- data/doc/top-level-namespace.html +2 -2
- data/enhanced_errors.gemspec +1 -1
- data/examples/demo_rspec.rb +16 -1
- data/lib/enhanced_errors.rb +48 -9
- metadata +3 -2
data/lib/enhanced_errors.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
334
|
-
|
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.
|
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-
|
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
|