debug_exceptions_json 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a0e8a0294484b5cc7449dcb6ab64409cdf0feb4
4
- data.tar.gz: 5117fa1b0e790b97aeda4307e2d4fece0c270022
3
+ metadata.gz: 36142c1f6eab432c336e9b73c1b440d597e27e2d
4
+ data.tar.gz: e9186312042ddf8a819df266a33f6fcda609a546
5
5
  SHA512:
6
- metadata.gz: c9fbb0c309e1ce30ff3c0eadcfdbde0553d8d77c3da6a5067775b42197ec8a74e1e2c85b094e4fbfa9383edff91d86aff0e239f26ddc87f626e43e77f268ef83
7
- data.tar.gz: eac559f5914261207ad457d786de6e542cb3d33e717749f0022f3c10d7657065acfd139359963e87aa639efea44de99611ea12445198f2d07e55497305eb90cc
6
+ metadata.gz: 7bf392be1ecd51cbc8be3f5358d925663077f20f82abae1b3d14316dafdb9afe421e7627e73fe63f73029e64c0be0153a6d8b0088cf3dcae9dc33e8a732521cc
7
+ data.tar.gz: 085c1e040d8455f70898eba1c198145f5548c7737b85d7f009c0d9c925a1887f9c761ba42af9b1911c3115899bf9d9d1834a666dd50b260bdb37895999cf8065
@@ -0,0 +1,2 @@
1
+ require 'debug_exceptions_json/rspec/hook'
2
+ require 'debug_exceptions_json/rspec/formatter'
@@ -0,0 +1,49 @@
1
+ class DebugExceptionsJson
2
+ module RSpec
3
+ class Formatter < ::RSpec::Core::Formatters::ProgressFormatter
4
+ ::RSpec::Core::Formatters.register self, :dump_failures
5
+
6
+ def dump_failures(notification)
7
+ return if notification.failure_notifications.empty?
8
+
9
+ colorizer = ::RSpec::Core::Formatters::ConsoleCodes
10
+ formatted = "\nFailures:\n"
11
+
12
+ notification.failure_notifications.each_with_index do |failure, index|
13
+ formatted << failure.fully_formatted(index.next, colorizer)
14
+ response = failure.example.metadata[:response]
15
+
16
+ if response.server_error?
17
+ begin
18
+ e = JSON(response.body)['error']
19
+ rescue JSON::ParserError
20
+ e = {}
21
+ end
22
+
23
+ if e['exception_class'] && e['message'] && e['backtrace']
24
+ formatted << error_to_dump_message(e)
25
+ end
26
+ end
27
+ end
28
+
29
+ output.puts formatted
30
+ end
31
+
32
+ private
33
+
34
+ # TODO: colorize server error dump?
35
+ def error_to_dump_message(error)
36
+ <<-EOM
37
+
38
+ ServerErrorDump:
39
+ exception class:
40
+ #{error['exception_class']}
41
+ message:
42
+ #{error['message']}
43
+ short_backtrace:
44
+ #{error['backtrace'][0..10].join("\n ")}
45
+ EOM
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ class DebugExceptionsJson
2
+ module RSpec
3
+ module Hook
4
+ def self.included(base)
5
+ base.instance_eval do
6
+ after do |example|
7
+ example.metadata[:response] = example.instance_exec { response }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  class DebugExceptionsJson
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug_exceptions_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki Ono
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -105,7 +105,9 @@ files:
105
105
  - MIT-LICENSE
106
106
  - Rakefile
107
107
  - lib/debug_exceptions_json.rb
108
- - lib/debug_exceptions_json/rspec/matchers.rb
108
+ - lib/debug_exceptions_json/rspec.rb
109
+ - lib/debug_exceptions_json/rspec/formatter.rb
110
+ - lib/debug_exceptions_json/rspec/hook.rb
109
111
  - lib/debug_exceptions_json/version.rb
110
112
  homepage: https://github.com/taiki45/debug_exceptions_json
111
113
  licenses:
@@ -1,81 +0,0 @@
1
- require 'rspec'
2
-
3
- class DebugExceptionsJson
4
- module RSpec
5
- module Matchers
6
- # TODO: Accept symbol version
7
- def have_status_code(expected_code)
8
- StatusCodeMatcher.new(expected_code)
9
- end
10
-
11
- class StatusCodeMatcher
12
- def initialize(expected_code)
13
- @expected = expected_code
14
- end
15
-
16
- def failure_message
17
- message = "expected the response to have status code #{@expected} but it was #{@actual}."
18
-
19
- if dump_exception?(@response)
20
- [message, dumped_exception].join("\n\n")
21
- else
22
- message
23
- end
24
- end
25
- alias :failure_message_for_should :failure_message
26
-
27
- def failure_message_when_negated
28
- message = "expected the response not to have status code #{@expected} but it did"
29
-
30
- if dump_exception?(@response)
31
- [message, dumped_exception].join("\n\n")
32
- else
33
- message
34
- end
35
- end
36
- alias :failure_message_for_should_not :failure_message_when_negated
37
-
38
- def description
39
- "respond with numeric status code #{@expected}"
40
- end
41
-
42
- # response - A Rack::Response
43
- def matches?(response)
44
- @response = response
45
- @actual = response.status
46
- @actual == @expected
47
- end
48
-
49
- private
50
-
51
- # Set `@body` in default_error_response?
52
- def dump_exception?(response)
53
- response.server_error? && response.content_type.json? && default_error_response?(response)
54
- end
55
-
56
- def default_error_response?(response)
57
- @body = JSON.parse(response.body)
58
- @body.has_key?('error') &&
59
- @body['error'].has_key?('message') &&
60
- @body['error'].has_key?('backtrace')
61
- rescue JSON::ParserError
62
- false
63
- end
64
-
65
- def dumped_exception
66
- error = @body['error']
67
-
68
- <<-EOM
69
- ServerError:
70
- exception class:
71
- #{error['exception_class']}
72
- message:
73
- #{error['message']}
74
- short_backtrace:
75
- #{error['backtrace'][0..10].join("\n ")}
76
- EOM
77
- end
78
- end
79
- end
80
- end
81
- end