enhanced_errors 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/enhanced_errors.gemspec +1 -1
- data/lib/enhanced_errors.rb +28 -29
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f31d5706d675b416846c7fe44cc1c6f6eb405489d574a9e9578aebee106109af
|
4
|
+
data.tar.gz: a5d31e4545534bfba158646f30d99bae1107086c51e20d1f8a5ad77454d74c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b79305f72e59ac8c615b137b6279c74d13156085d698bcc6efaf0d6c637bd489d6bfe1e93bfc1aede2673abe60033b3e64111b07b4916b4fe880f417684bfdbd
|
7
|
+
data.tar.gz: 97c791940c780ee0952e82f256b640923ba59623052224ec0c3ca5d84bf57a471f349e281cea82c0f00976dbba497a62bdc39fa5f1115d655e96baa980d0215c
|
data/enhanced_errors.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "enhanced_errors"
|
3
|
-
spec.version = "3.0.
|
3
|
+
spec.version = "3.0.3"
|
4
4
|
spec.authors = ["Eric Beland"]
|
5
5
|
|
6
6
|
spec.summary = "Automatically enhance your errors with messages containing variable values from the moment they were raised."
|
data/lib/enhanced_errors.rb
CHANGED
@@ -161,25 +161,22 @@ class EnhancedErrors
|
|
161
161
|
|
162
162
|
def override_rspec_message(example, binding_or_bindings)
|
163
163
|
exception_obj = example.exception
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
164
|
+
return if exception_obj.nil?
|
165
|
+
|
166
|
+
from_bindings = [binding_or_bindings].flatten.compact
|
167
|
+
case exception_obj.class.to_s
|
168
|
+
when 'RSpec::Core::MultipleExceptionError'
|
168
169
|
exception_obj.all_exceptions.each do |exception|
|
169
|
-
override_exception_message(exception,
|
170
|
+
override_exception_message(exception, from_bindings + exception.binding_infos)
|
170
171
|
end
|
171
|
-
|
172
|
+
when 'RSpec::Expectations::ExpectationNotMetError'
|
172
173
|
override_exception_message(exception_obj, binding_or_bindings)
|
174
|
+
else
|
175
|
+
override_exception_message(exception_obj, from_bindings + exception_obj.binding_infos)
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
176
179
|
def override_exception_message(exception, binding_or_bindings)
|
177
|
-
return nil unless exception && exception.respond_to?(:message)
|
178
|
-
test_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
|
179
|
-
exception_binding = (exception.binding_infos.length > 0)
|
180
|
-
has_message = !(exception.respond_to?(:unaltered_message))
|
181
|
-
return nil unless (test_binding || exception_binding) && has_message
|
182
|
-
|
183
180
|
variable_str = EnhancedErrors.format(binding_or_bindings)
|
184
181
|
message_str = exception.message
|
185
182
|
exception.define_singleton_method(:unaltered_message) { message_str }
|
@@ -281,35 +278,37 @@ class EnhancedErrors
|
|
281
278
|
@capture_next_binding = false
|
282
279
|
@rspec_tracepoint&.disable
|
283
280
|
|
284
|
-
@rspec_tracepoint = TracePoint.new(:raise
|
285
|
-
# puts "name #{tp.raised_exception.class.name rescue ''} method:#{tp.method_id} tp.binding:#{tp.binding.local_variables rescue ''}"
|
286
|
-
# puts "event: #{tp.event} defined_class#{class_to_string(tp.defined_class)} #{tp.path}:#{tp.lineno} #{tp.callee_id} "
|
287
|
-
# This trickery below is to help us identify the anonymous block return we want to grab
|
288
|
-
# Very kluge-y and edge cases have grown it, but it works
|
289
|
-
if tp.event == :b_return
|
290
|
-
if RSPEC_HANDLER_NAMES.include?(class_to_string(tp.defined_class))
|
291
|
-
@capture_next_binding = :next
|
292
|
-
next
|
293
|
-
end
|
294
|
-
next unless @capture_next_binding
|
295
|
-
if @capture_next_binding == :next || @capture_next_binding == :next_matching && is_rspec_example?(tp)
|
296
|
-
@capture_next_binding = false
|
297
|
-
@rspec_example_binding = tp.binding
|
298
|
-
end
|
299
|
-
elsif tp.event == :raise
|
281
|
+
@rspec_tracepoint = TracePoint.new(:raise) do |tp|
|
300
282
|
class_name = tp.raised_exception.class.name
|
301
283
|
case class_name
|
302
284
|
when 'RSpec::Expectations::ExpectationNotMetError'
|
303
|
-
|
285
|
+
start_rspec_binding_trap
|
304
286
|
else
|
305
287
|
handle_tracepoint_event(tp)
|
306
288
|
end
|
307
289
|
end
|
308
290
|
end
|
309
291
|
@rspec_tracepoint.enable
|
292
|
+
end
|
293
|
+
|
294
|
+
# grab the next rspec binding that goes by, and then stop the expensive listening trace
|
295
|
+
def start_rspec_binding_trap
|
296
|
+
@rspec_binding_trap = TracePoint.new(:b_return) do |tp|
|
297
|
+
# kluge-y hack and will be a pain to maintain
|
298
|
+
if tp.callee_id == :handle_matcher
|
299
|
+
@capture_next_binding = :next
|
300
|
+
next
|
301
|
+
end
|
302
|
+
next unless @capture_next_binding
|
303
|
+
@capture_next_binding = false
|
304
|
+
@rspec_example_binding = tp.binding
|
305
|
+
@rspec_binding_trap.disable
|
306
|
+
@rspec_binding_trap = nil
|
310
307
|
end
|
308
|
+
@rspec_binding_trap.enable
|
311
309
|
end
|
312
310
|
|
311
|
+
|
313
312
|
def stop_rspec_binding_capture
|
314
313
|
mutex.synchronize do
|
315
314
|
@rspec_tracepoint&.disable
|