kinetic_cafe_error 1.5 → 1.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
  SHA1:
3
- metadata.gz: 685467959030041afef309c2d80dee6de147f013
4
- data.tar.gz: 0a56fd7578757bb16eabed95380d65a4e6b6e9e1
3
+ metadata.gz: 37643698d0f31692802e45814d1ef9fa5dd03bb1
4
+ data.tar.gz: 91419c4aa9df887087a7629c4b6e4e2a4a140554
5
5
  SHA512:
6
- metadata.gz: ff170e4595486ceb5b125626acaa21397e0ea8663d8d86e27444dc058ca3b7584c93b1ed6929c2e6d80d6e351a4fdbc26b39712d93ac44463127b66055a7e430
7
- data.tar.gz: c709887413f3535270948786c73fb5641a7038a8d4363adf83afc2151a752f046502d78bb5feb28ec17adfa1d1a42be86e0a746d67e86278b6c06d9bbcc46d3f
6
+ metadata.gz: 5415ff4c3bc5b8b5e75b104bfc1bb453450964ca850a9844b7b0895486826e21dbd6405d64c0e320a7822b9c3412941fb11c2c7d30161b1e10aaa434b706c9a3
7
+ data.tar.gz: ea8288a297cf85abc62c1420f83f3f6c6bbc68a193e97fc8812845ed6ceb39b92b6d0b8cc57d4d5269b84a0042c8ff4abfe79b9a4005d1a95e3d2fbec3fd7751
data/History.rdoc CHANGED
@@ -1,4 +1,18 @@
1
- === 1.5 / 2015-07-28
1
+ === 1.6 / 2015-07-30
2
+
3
+ * 2 minor enhancements:
4
+
5
+ * Improve the Minitest and RSpec test helpers so that they ignore the error
6
+ +cause+ if it is not included as part of the assertion. The specification
7
+ of the +cause+ is recommended if you have specific values you want to
8
+ compare.
9
+
10
+ * Improve +kinetic_cafe_error_handler+ so that if it is called with an error
11
+ class instead of an instance of an error, it will construct the error
12
+ instance with the provided parameters. This makes custom +rescue_from+
13
+ constructions cleaner.
14
+
15
+ === 1.5 / 2015-07-29
2
16
 
3
17
  * 2 bug fixes:
4
18
 
@@ -40,7 +40,28 @@ module KineticCafe::ErrorHandler
40
40
  # HTML is rendered with #kinetic_cafe_error_render_html. JSON is rendered
41
41
  # with #kinetic_cafe_error_render_json. Either of these can be overridden in
42
42
  # controllers for different behaviour.
43
- def kinetic_cafe_error_handler(error)
43
+ #
44
+ # As an option, +kinetic_cafe_error_handler+ can also be used in a
45
+ # +rescue_from+ block with an error class and parameters, and it will
46
+ # construct the error for handling. The following example assumes that there
47
+ # is an error called ObjectNotFound.
48
+ #
49
+ # rescue_from ActiveRecord::NotFound do |error|
50
+ # kinetic_cafe_error_handler KineticCafe::Error::ObjectNotFound,
51
+ # cause: error
52
+ # end
53
+ #
54
+ # This would be the same as:
55
+ #
56
+ # rescue_from ActiveRecord::NotFound do |error|
57
+ # kinetic_cafe_error_handler KineticCafe::Error::ObjectNotFound.new(
58
+ # cause: error
59
+ # )
60
+ # end
61
+ def kinetic_cafe_error_handler(error, error_params = {})
62
+ # If the error provided is actually an error class, make an error instance.
63
+ error.kind_of?(KineticCafe::ErrorDSL) && error = error.new(error_params)
64
+
44
65
  kinetic_cafe_error_log_error(error)
45
66
 
46
67
  respond_to do |format|
@@ -4,6 +4,9 @@ module Minitest #:nodoc:
4
4
  # Assert that the +actual+ exception received is the +expected+ descendant
5
5
  # of KineticCafe::Error and that it has been constructed with the same
6
6
  # +params+ provided.
7
+ #
8
+ # If a +cause+ is not provided, any cause on the received error will be
9
+ # ignored.
7
10
  def assert_kc_error expected, actual, params = {}, msg = nil
8
11
  msg, params = params, {} if msg.nil? && params.kind_of?(String)
9
12
 
@@ -13,6 +16,15 @@ module Minitest #:nodoc:
13
16
  assert_kind_of expected, actual,
14
17
  msg || "Expected #{actual} to be #{expected}, but it was not."
15
18
 
19
+ unless params.key?(:cause)
20
+ actual = actual.dup
21
+ actual.instance_variable_set(:@cause, nil)
22
+ actual.instance_variable_set(:@initialized_cause, true)
23
+ actual.instance_variable_get(:@i18n_params).tap do |params|
24
+ params.delete(:cause)
25
+ end
26
+ end
27
+
16
28
  expected = expected.new(params)
17
29
  assert_equal expected, actual,
18
30
  msg || "Expected #{actual} to be #{expected}, but it was not."
@@ -26,11 +38,26 @@ module Minitest #:nodoc:
26
38
  # output is compared, not KineticCafe::Error objects. The JSON for the
27
39
  # provided KineticCafe::Error object is generated through
28
40
  # KineticCafe::Error#error_json.
41
+ #
42
+ # If a +cause+ is not provided, any cause on the received error will be
43
+ # ignored.
29
44
  def assert_kc_error_json expected, actual, params = {}, msg = nil
30
45
  msg, params = params, {} if msg.nil? && params.kind_of?(String)
31
46
 
32
47
  msg ||= "Expected #{actual} to be JSON for #{expected}, but it was not."
33
48
  actual = JSON.parse(actual)
49
+
50
+ unless params.key?(:cause)
51
+ actual['error'].tap do |error|
52
+ error.delete('cause')
53
+ if error['i18n_params']
54
+ error['i18n_params'].delete('cause')
55
+ error.delete('i18n_params') if error['i18n_params'].empty?
56
+ end
57
+ end
58
+ actual
59
+ end
60
+
34
61
  expected = JSON.parse(expected.new(params).error_result.to_json)
35
62
 
36
63
  assert_equal expected, actual, msg
@@ -25,7 +25,7 @@ module KineticCafe # :nodoc:
25
25
  # rescue clause and handled there, as is shown in the included
26
26
  # KineticCafe::ErrorHandler controller concern for Rails.
27
27
  class Error < ::StandardError
28
- VERSION = '1.5' # :nodoc:
28
+ VERSION = '1.6' # :nodoc:
29
29
 
30
30
  # Get the KineticCafe::Error functionality.
31
31
  include KineticCafe::ErrorModule
@@ -73,6 +73,7 @@ module KineticCafe # :nodoc:
73
73
  @extra = options.delete(:extra)
74
74
 
75
75
  @initialized_cause = false
76
+ @cause = nil
76
77
  initialize_cause(options.delete(:cause)) if options.key?(:cause)
77
78
 
78
79
  query = options.delete(:query)
@@ -40,6 +40,16 @@ module KineticCafe
40
40
  match do |actual|
41
41
  expect(actual).to be_kind_of(KineticCafe::ErrorModule)
42
42
  expect(actual).to be_kind_of(expected)
43
+
44
+ unless params.key?(:cause)
45
+ actual = actual.dup
46
+ actual.instance_variable_set(:@cause, nil)
47
+ actual.instance_variable_set(:@initialized_cause, true)
48
+ actual.instance_variable_get(:@i18n_params).tap do |params|
49
+ params.delete(:cause)
50
+ end
51
+ end
52
+
43
53
  expect(actual).to eq(expected.new(params))
44
54
  end
45
55
 
@@ -48,6 +58,17 @@ module KineticCafe
48
58
 
49
59
  matcher :be_kc_error_json do |expected, params = {}|
50
60
  match do |actual|
61
+ unless params.key?(:cause)
62
+ actual['error'].tap do |error|
63
+ error.delete('cause')
64
+ if error['i18n_params']
65
+ error['i18n_params'].delete('cause')
66
+ error.delete('i18n_params') if error['i18n_params'].empty?
67
+ end
68
+ end
69
+ actual
70
+ end
71
+
51
72
  expect(actual).to \
52
73
  be_json_for(JSON.parse(expected.new(params).error_result.to_json))
53
74
  end
@@ -161,7 +161,7 @@ describe KineticCafe::Error do
161
161
  end
162
162
  end
163
163
 
164
- it 'captures the causting exception' do
164
+ it 'captures the causing exception' do
165
165
  refute_nil @wrapping_exception.cause, 'No exception captured'
166
166
  assert_equal @causing_exception, @wrapping_exception.cause
167
167
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kinetic_cafe_error
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.5'
4
+ version: '1.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest