debug_exceptions_json 0.0.1 → 0.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a80d5c215ac22aaa68b3deffb3aaad771ce24ad
|
4
|
+
data.tar.gz: 00da8f07476df8a9bad7abd8f8538b7e36ea2a5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87843ac9e42b2087744fc258151f0cb77a999d3212a02a8413fbbb7d79bb6a678457ccffb6447a12d449a1c4a01cee4e9780dc9db127c389889bbced06b23884
|
7
|
+
data.tar.gz: 2be167e9d5f129384081bb2e02f7548b0ae5ac683cd0f877827d880d678f796857b9c5f20818edd57745c840e58dce5ee6c650c4342389bd755657f89441664c
|
@@ -0,0 +1,81 @@
|
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_exceptions_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taiki Ono
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- MIT-LICENSE
|
106
106
|
- Rakefile
|
107
107
|
- lib/debug_exceptions_json.rb
|
108
|
+
- lib/debug_exceptions_json/rspec/matchers.rb
|
108
109
|
- lib/debug_exceptions_json/version.rb
|
109
110
|
homepage: https://github.com/taiki45/debug_exceptions_json
|
110
111
|
licenses:
|