debug_exceptions_json 0.1.0 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36142c1f6eab432c336e9b73c1b440d597e27e2d
|
4
|
+
data.tar.gz: e9186312042ddf8a819df266a33f6fcda609a546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf392be1ecd51cbc8be3f5358d925663077f20f82abae1b3d14316dafdb9afe421e7627e73fe63f73029e64c0be0153a6d8b0088cf3dcae9dc33e8a732521cc
|
7
|
+
data.tar.gz: 085c1e040d8455f70898eba1c198145f5548c7737b85d7f009c0d9c925a1887f9c761ba42af9b1911c3115899bf9d9d1834a666dd50b260bdb37895999cf8065
|
@@ -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
|
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.
|
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-
|
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
|
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
|