enhanced_errors 2.0.5 → 2.0.6

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: 3897d29e868998ef225633f9f0f0f99a994b55563d65bff843ade348e7229bb9
4
- data.tar.gz: 37f1db45f0c18c64846d396088f71bab2312b89da1a375b4d325309832983efc
3
+ metadata.gz: 9e6ed241407a54376e0c64f2c1adc087e3dae4980ac5b7e84c947d92ff787392
4
+ data.tar.gz: 4f949a5145869e73e7f795a9c009800433956162a6d25695c2a9e8ba3a39da05
5
5
  SHA512:
6
- metadata.gz: b156387888d9479f5d474808a922127fbfc5c6ed7035c6d8ef552dabca39b550655e191bfc6f0f11d64db36ded66fe03619cca7eaff2f5b725abb3d106f07d87
7
- data.tar.gz: ce0fcadb20a8be1f0b53921cf990e5c458ce6ba1099dc5b9ceff1c8459ab82b707234bfbf964b10036a5b37a33b0248337d0289005b0f32c61933efa25ef44de
6
+ metadata.gz: 02312f5287c4214c59b4b4a53e723d53d4dff511f24c335a7f7a84f049bb06638f77ea22f488cba5682fba66f581116b2bb1a4b3a79d8b6a5a290f5f822f1ea8
7
+ data.tar.gz: 13d06fa670a3f34bb67624ec40bc9a87810536aace8c2867e64620092c13d8e48d25675241491d821491cb2f3a893c1d8faa2ede7ff2f22c45b50fb506fbbd74
data/README.md CHANGED
@@ -79,33 +79,19 @@ exceptions except those that pass by during the RSpec run.
79
79
  ```ruby
80
80
 
81
81
  RSpec.configure do |config|
82
-
83
- # add these config changes to your RSpec config to get variable messages
84
- config.before(:suite) do
85
- RSpec::Core::Example.prepend(Enhanced::Integrations::RSpecErrorFailureMessage)
86
- end
87
-
88
82
  config.before(:example) do |_example|
89
83
  EnhancedErrors.start_rspec_binding_capture
90
84
  end
91
85
 
92
86
  config.after(:example) do |example|
93
87
  example.metadata[:expect_binding] = EnhancedErrors.stop_rspec_binding_capture
88
+ EnhancedErrors.override_exception_message(example.exception, example.metadata[:expect_binding])
94
89
  end
95
-
96
90
  end
97
-
98
91
  ```
99
92
 
100
- ## Minitest
101
-
102
- Untested as of yet, but enhance_exceptions!(override_messages: true) is likely to work.
93
+ ## TODO: Minitest
103
94
 
104
- If anyone wants to look into an integration implementation like RSpec, it would
105
- be welcomed. With a more targeted approach like the RSpec one, exceptions could be captured and
106
- modified only during test time, like the RSpec approach. This would be advantageous as
107
- it wouldn't modify the exception message itself, but still makes the variable output available in
108
- test messages.
109
95
 
110
96
  ## Enhancing .message
111
97
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "2.0.5"
3
+ spec.version = "2.0.6"
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."
@@ -3,14 +3,13 @@
3
3
  require 'set'
4
4
  require 'json'
5
5
 
6
- require_relative 'enhanced/integrations/rspec_error_failure_message'
7
6
  require_relative 'enhanced/colors'
8
7
 
9
8
  IGNORED_EXCEPTIONS = %w[SystemExit NoMemoryError SignalException Interrupt
10
- ScriptError LoadError NotImplementedError SyntaxError
11
- RSpec::Expectations::ExpectationNotMetError
12
- RSpec::Matchers::BuiltIn::RaiseError
13
- SystemStackError Psych::BadAlias]
9
+ ScriptError LoadError NotImplementedError SyntaxError
10
+ RSpec::Expectations::ExpectationNotMetError
11
+ RSpec::Matchers::BuiltIn::RaiseError
12
+ SystemStackError Psych::BadAlias]
14
13
 
15
14
  class EnhancedErrors
16
15
  extend ::Enhanced
@@ -106,7 +105,8 @@ class EnhancedErrors
106
105
  # and modifies the exceptions .message to display the variables
107
106
  def override_exception_message(exception, binding_or_bindings)
108
107
  # Ensure binding_or_bindings is always an array for compatibility
109
- return exception if binding_or_bindings.nil? || binding_or_bindings.empty? || exception.respond_to?(:unaltered_message)
108
+ return exception if binding_or_bindings.nil? || binding_or_bindings.empty?
109
+ return exception if exception.respond_to?(:unaltered_message)
110
110
  variable_str = EnhancedErrors.format(binding_or_bindings)
111
111
  message_str = exception.message
112
112
  exception.define_singleton_method(:unaltered_message) { message_str }
@@ -186,26 +186,36 @@ class EnhancedErrors
186
186
  puts "Failed to prepend RSpec custom failure message: #{e.message}"
187
187
  end
188
188
 
189
-
190
189
  def start_rspec_binding_capture
191
190
  @rspec_example_binding = nil
191
+ @capture_next_binding = false
192
192
 
193
193
  # In the Exception binding infos, I observed that re-setting
194
194
  # the tracepoint without disabling it seemed to accumulate traces
195
195
  # in the test suite where things are disabled and re-enabled often.
196
196
  @rspec_tracepoint&.disable
197
197
 
198
- @rspec_tracepoint = TracePoint.new(:b_return) do |tp|
198
+ @rspec_tracepoint = TracePoint.new(:raise, :b_return) do |tp|
199
199
  # This is super-kluge-y and should be replaced with... something TBD
200
-
201
- # early easy checks to nope out of the object name and other checks
202
- if tp.method_id.nil? && !(tp.path.include?('rspec')) && tp.path.end_with?('_spec.rb')
203
- # fixes cases where class and name are screwed up or overridden
204
- if determine_object_name(tp) =~ RSPEC_EXAMPLE_REGEXP
205
- @rspec_example_binding = tp.binding
200
+ # only look at block returns once we have seen an ExpectationNotMetError
201
+
202
+ case tp.event
203
+ when :b_return
204
+ # only active if we are capturing the next binding
205
+ next unless @capture_next_binding && @rspec_example_binding.nil?
206
+ # early easy checks to nope out of the object name and other checks
207
+ if @capture_next_binding && tp.method_id.nil? && !(tp.path.include?('rspec')) && tp.path.end_with?('_spec.rb')
208
+ # fixes cases where class and name are screwed up or overridden
209
+ if determine_object_name(tp) =~ RSPEC_EXAMPLE_REGEXP
210
+ @rspec_example_binding = tp.binding
211
+ end
212
+ end
213
+ when :raise
214
+ # turn on capture of next binding
215
+ if tp.raised_exception.class.name == 'RSpec::Expectations::ExpectationNotMetError'
216
+ @capture_next_binding ||= true
206
217
  end
207
218
  end
208
-
209
219
  end
210
220
 
211
221
  @rspec_tracepoint.enable
@@ -214,6 +224,7 @@ class EnhancedErrors
214
224
  def stop_rspec_binding_capture
215
225
  @rspec_tracepoint&.disable
216
226
  binding_info = convert_binding_to_binding_info(@rspec_example_binding) if @rspec_example_binding
227
+ @capture_next_binding = false
217
228
  @rspec_example_binding = nil
218
229
  binding_info
219
230
  end
@@ -621,7 +632,7 @@ class EnhancedErrors
621
632
 
622
633
  def variable_description(vars_hash)
623
634
  vars_hash.map do |name, value|
624
- " #{Colors.purple(name)}: #{format_variable(value)}\n"
635
+ " #{Colors.purple(name)}: #{format_variable(value)}\n"
625
636
  end.join
626
637
  rescue
627
638
  ''
@@ -691,4 +702,4 @@ class EnhancedErrors
691
702
  !ignored && !rspec
692
703
  end
693
704
  end
694
- end
705
+ 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.0.5
4
+ version: 2.0.6
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-12 00:00:00.000000000 Z
11
+ date: 2024-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -96,7 +96,6 @@ files:
96
96
  - examples/example_spec.rb
97
97
  - lib/enhanced/colors.rb
98
98
  - lib/enhanced/exception.rb
99
- - lib/enhanced/integrations/rspec_error_failure_message.rb
100
99
  - lib/enhanced_errors.rb
101
100
  homepage: https://github.com/ericbeland/enhanced_errors
102
101
  licenses: []
@@ -1,13 +0,0 @@
1
- module Enhanced
2
- module Integrations
3
- module RSpecErrorFailureMessage
4
- def execution_result
5
- result = super
6
- if result.exception
7
- EnhancedErrors.override_exception_message(result.exception, self.metadata[:expect_binding])
8
- end
9
- result
10
- end
11
- end
12
- end
13
- end