kinetic_cafe_error 1.4.1 → 1.5

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: e3b2150c91bd7c20a1915ba1f68ec3ac50dc20bf
4
- data.tar.gz: a44989aafb6044dcbe837a3d808e3c3bda6400dd
3
+ metadata.gz: 685467959030041afef309c2d80dee6de147f013
4
+ data.tar.gz: 0a56fd7578757bb16eabed95380d65a4e6b6e9e1
5
5
  SHA512:
6
- metadata.gz: 3f730616093adfc5fe2730af14749eafa0333881d04640518a2b75f9dcb53e01b6d636e512e45158de16163a26cac6799301386bb4572cd51cfbf910e3cfc8c1
7
- data.tar.gz: 4f8ecaa344b865a66c0d4544940703bc643b41a22b4d7f7c1a19bc26b3e7c92cea72706172d6c709828f875aadf26407b7fad59e144c3dfa716602e991ea0fd8
6
+ metadata.gz: ff170e4595486ceb5b125626acaa21397e0ea8663d8d86e27444dc058ca3b7584c93b1ed6929c2e6d80d6e351a4fdbc26b39712d93ac44463127b66055a7e430
7
+ data.tar.gz: c709887413f3535270948786c73fb5641a7038a8d4363adf83afc2151a752f046502d78bb5feb28ec17adfa1d1a42be86e0a746d67e86278b6c06d9bbcc46d3f
data/.travis.yml CHANGED
@@ -6,8 +6,7 @@ rvm:
6
6
  - 2.0.0
7
7
  - 1.9.3
8
8
  - jruby-1.7
9
- - jruby-9.0.0.0.pre2
10
- - jruby-19mode
9
+ - jruby-9.0.0.0
11
10
  - jruby-head
12
11
  - ruby-head
13
12
  - rbx-2
@@ -15,7 +14,6 @@ matrix:
15
14
  allow_failures:
16
15
  - rvm: rbx-2
17
16
  - rvm: jruby-head
18
- - rvm: jruby-9.0.0.0.pre2
19
17
  - rvm: ruby-head
20
18
  gemfile:
21
19
  - Gemfile
data/History.rdoc CHANGED
@@ -1,3 +1,22 @@
1
+ === 1.5 / 2015-07-28
2
+
3
+ * 2 bug fixes:
4
+
5
+ * Handle error causes correctly for Ruby 2.1 or later, where <tt>raise
6
+ Exception, cause: RuntimeError.new</tt> does not pass the +cause+ the
7
+ exception constructor, but it still sets the cause correctly on the
8
+ exception. These changes make this correct for both +raise+ construction
9
+ and normal construction.
10
+
11
+ * The RSpec helpers did not work because they spelled the class +Rspec+, not
12
+ +RSpec+. This has been fixed.
13
+
14
+ * 2 development changes:
15
+
16
+ * Fixed some test typos.
17
+
18
+ * Add i18n-tasks for CSV exports.
19
+
1
20
  === 1.4.1 / 2015-07-08
2
21
 
3
22
  * 1 bug fix
data/Rakefile CHANGED
@@ -35,6 +35,8 @@ spec = Hoe.spec 'kinetic_cafe_error' do
35
35
  extra_dev_deps << ['minitest-stub-const', '~> 0.4']
36
36
  extra_dev_deps << ['rack-test', '~> 0.6']
37
37
  extra_dev_deps << ['rake', '~> 10.0']
38
+ extra_dev_deps << ['i18n-tasks', '~> 0.8']
39
+ extra_dev_deps << ['i18n-tasks-csv', '~> 1.0']
38
40
  extra_dev_deps << ['rubocop', '~> 0.32']
39
41
  extra_dev_deps << ['simplecov', '~> 0.7']
40
42
  extra_dev_deps << ['coveralls', '~> 0.8']
@@ -28,7 +28,7 @@ module KineticCafe::ErrorHandler
28
28
  def kinetic_cafe_error_handler_log_locale(locale = nil)
29
29
  self.__kinetic_cafe_error_handler_log_locale = locale if locale
30
30
  self.__kinetic_cafe_error_handler_log_locale ||= I18n.default_locale
31
- self.__kinetic_cafe_error_handler_log_locale
31
+ __kinetic_cafe_error_handler_log_locale
32
32
  end
33
33
  end
34
34
 
@@ -109,3 +109,11 @@ ignore_eq_base:
109
109
  ## Ignore these keys completely:
110
110
  # ignore:
111
111
  # - kaminari.*
112
+
113
+ <% require 'i18n-tasks-csv' %>
114
+
115
+ csv:
116
+ export:
117
+ - tmp/i18n-export/kinetic_cafe_error.csv
118
+ import:
119
+ - tmp/i18n-export/kinetic_cafe_error.csv
@@ -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.4.1' # :nodoc:
28
+ VERSION = '1.5' # :nodoc:
29
29
 
30
30
  # Get the KineticCafe::Error functionality.
31
31
  include KineticCafe::ErrorModule
@@ -9,8 +9,25 @@ module KineticCafe # :nodoc:
9
9
  # Extra data relevant to recipients of the exception, provided on
10
10
  # construction.
11
11
  attr_reader :extra
12
- # The exception that caused this exception; provided on construction.
13
- attr_reader :cause
12
+ ##
13
+ # :attr_reader:
14
+ # The exception that caused this exception. Provided on exception
15
+ # construction or automatically through Ruby’s standard exception
16
+ # mechanism.
17
+ def cause
18
+ unless @initialized_cause
19
+ begin
20
+ initialize_cause(super) if !@initialized_cause && super
21
+ rescue NoMethodError
22
+ # We are suppressing this error because Exception#cause was
23
+ # implemented in Ruby 2.1.
24
+ @initialized_cause = true
25
+ @cause = nil
26
+ end
27
+ end
28
+
29
+ @cause
30
+ end
14
31
 
15
32
  # Create a new error with the given parameters.
16
33
  #
@@ -25,7 +42,8 @@ module KineticCafe # :nodoc:
25
42
  # +i18n_params+:: The parameters to be sent to I18n.translate with the
26
43
  # #i18n_key.
27
44
  # +cause+:: The exception that caused this error. Used to wrap an earlier
28
- # exception.
45
+ # exception. This is only necessary for Ruby before 2.1 or when
46
+ # directly initializing the exception.
29
47
  # +extra+:: Extra data to be returned in the API representation of this
30
48
  # exception.
31
49
  # +query+:: A hash of parameters added to +i18n_params+, typically from
@@ -53,14 +71,13 @@ module KineticCafe # :nodoc:
53
71
  @status = options.delete(:status) || default_status
54
72
  @i18n_params = options.delete(:i18n_params) || {}
55
73
  @extra = options.delete(:extra)
56
- @cause = options.delete(:cause)
57
74
 
58
- @i18n_params.update(cause: cause.message) if cause
75
+ @initialized_cause = false
76
+ initialize_cause(options.delete(:cause)) if options.key?(:cause)
59
77
 
60
78
  query = options.delete(:query)
61
79
  @i18n_params.merge!(query: stringify(query)) if query
62
80
  @i18n_params.merge!(options)
63
- @i18n_params.freeze
64
81
  end
65
82
 
66
83
  # The message associated with this exception. If not provided, defaults to
@@ -161,6 +178,20 @@ module KineticCafe # :nodoc:
161
178
  "cause=#{cause}>"
162
179
  end
163
180
 
181
+ private
182
+
183
+ def initialize_cause(cause)
184
+ return if cause.nil?
185
+
186
+ unless cause.kind_of? Exception
187
+ fail ArgumentError, 'cause must be an Exception'
188
+ end
189
+
190
+ @initialized_cause = true
191
+ @cause = cause
192
+ @i18n_params.update(cause: @cause.message)
193
+ end
194
+
164
195
  class << self
165
196
  ##
166
197
  # The base for I18n key resolution. Defaults to 'kcerrors'.
@@ -5,8 +5,8 @@ module KineticCafe
5
5
  # these with:
6
6
  #
7
7
  # require 'kinetic_cafe/error_rspec'
8
- # Rspec.configure do |c|
9
- # c.include KineticCafe::ErrorRspec
8
+ # RSpec.configure do |c|
9
+ # c.include KineticCafe::ErrorRSpec
10
10
  # end
11
11
  #
12
12
  # +be_json_for+:: Verifies that the expected value is a JSON representation
@@ -20,8 +20,8 @@ module KineticCafe
20
20
  #
21
21
  # +be_kc_error_html+:: Verifies that the rendered HTML matches the output of
22
22
  # KineticCafe::Error.
23
- module ErrorRspec
24
- extend ::Rspec::Matchers::DSL
23
+ module ErrorRSpec
24
+ extend ::RSpec::Matchers::DSL
25
25
 
26
26
  matcher :be_json_for do |expected|
27
27
  match do |actual|
@@ -13,7 +13,7 @@ describe KineticCafe::Error do
13
13
  end
14
14
  end
15
15
 
16
- describe '#messsage and #i18n_message' do
16
+ describe '#message and #i18n_message' do
17
17
  it 'returns key/params if I18n.translate is not defined' do
18
18
  Object.stub_remove_const(:I18n) do
19
19
  assert_equal [ 'kcerrors.error', {} ], exception.i18n_message
@@ -145,4 +145,33 @@ describe KineticCafe::Error do
145
145
  assert_empty KineticCafe::Error.i18n_params
146
146
  end
147
147
  end
148
+
149
+ describe 'handles causing exceptions' do
150
+ before do
151
+ begin
152
+ begin
153
+ fail 'causing'
154
+ rescue => ex
155
+ @causing_exception = ex
156
+ raise KineticCafe::Error, cause: @causing_exception,
157
+ message: 'wrapping'
158
+ end
159
+ rescue => ex
160
+ @wrapping_exception = ex
161
+ end
162
+ end
163
+
164
+ it 'captures the causting exception' do
165
+ refute_nil @wrapping_exception.cause, 'No exception captured'
166
+ assert_equal @causing_exception, @wrapping_exception.cause
167
+ end
168
+
169
+ it 'puts the cause message in i18n_params when the cause is requested' do
170
+ refute_nil @wrapping_exception.cause, 'No exception captured'
171
+ assert_equal(
172
+ { cause: 'causing' },
173
+ @wrapping_exception.instance_variable_get(:@i18n_params)
174
+ )
175
+ end
176
+ end
148
177
  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.4.1
4
+ version: '1.5'
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-08 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -206,6 +206,34 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '10.0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: i18n-tasks
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.8'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.8'
223
+ - !ruby/object:Gem::Dependency
224
+ name: i18n-tasks-csv
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1.0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '1.0'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: rubocop
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -343,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
343
371
  version: '0'
344
372
  requirements: []
345
373
  rubyforge_project:
346
- rubygems_version: 2.4.5
374
+ rubygems_version: 2.4.8
347
375
  signing_key:
348
376
  specification_version: 4
349
377
  summary: kinetic_cafe_error provides an API-smart error base class and a DSL for defining