enhanced_errors 3.0.2 → 3.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbb09107f2f0aa86f1d75a293adaa6088123f46bec7b93d2e521e27a7619b829
4
- data.tar.gz: a735a7ae935b3718d24f391e55ca7685fafe507ed8ca72a6f79aca07422aad5e
3
+ metadata.gz: f31d5706d675b416846c7fe44cc1c6f6eb405489d574a9e9578aebee106109af
4
+ data.tar.gz: a5d31e4545534bfba158646f30d99bae1107086c51e20d1f8a5ad77454d74c23
5
5
  SHA512:
6
- metadata.gz: 8de7cf2dddc8b575d191605a060a55c56fe13867edbd3b81de2c4fd21905f28de88695dd5e5b5de7a36dce5195165587977f1d3151edd2e19207efe8aac93ee7
7
- data.tar.gz: 227b68eaeaa3050e9566067041d322ec121ae9331dad1e6bbed8686766efdcdc2608ab25dadce266acd04190ea490b8b347f5fb0710d785d9c7b0aedccc452c9
6
+ metadata.gz: b79305f72e59ac8c615b137b6279c74d13156085d698bcc6efaf0d6c637bd489d6bfe1e93bfc1aede2673abe60033b3e64111b07b4916b4fe880f417684bfdbd
7
+ data.tar.gz: 97c791940c780ee0952e82f256b640923ba59623052224ec0c3ca5d84bf57a471f349e281cea82c0f00976dbba497a62bdc39fa5f1115d655e96baa980d0215c
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "3.0.2"
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."
@@ -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
- case exception_obj
165
- when nil
166
- return nil
167
- when RSpec::Core::MultipleExceptionError
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, binding_or_bindings)
170
+ override_exception_message(exception, from_bindings + exception.binding_infos)
170
171
  end
171
- else
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, :b_return) do |tp|
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
- @capture_next_binding = :next_matching
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enhanced_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland