rspec-httpd 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rspec/httpd/expectation_failed.rb +13 -32
- data/lib/rspec/httpd.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7277e2b07cd04cb4c8a87062b2449244747ba07c032bfaf8b05d3d9b8e0a4761
|
4
|
+
data.tar.gz: c4974c0f457fbbd03c15d55d28408da3d1d6831509f5e56d7c1bb26dd80d2a10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84eed9b38ea95f413ea42b981cb761b32b3e10885a5177fda369a4c2b14ba29ef130c4ad76fa4988c7ade0eecf7c2294f3599ac2cdeff7d1e3a7eec655fa3996
|
7
|
+
data.tar.gz: aeba7bb613f2664b801881377bbac3371eb75aae5a7c04a05f50ee9bb47cf69eea9e346e7f9b0c2d9ca8a6e0b10860cf93f3432be1188c38c5d33bed12eabe80
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
@@ -1,39 +1,20 @@
|
|
1
|
+
# rubocop:disable Metrics/AbcSize
|
2
|
+
|
1
3
|
class RSpec::Httpd::ExpectationFailed < RuntimeError
|
2
|
-
attr_reader :original_error, :request
|
4
|
+
attr_reader :original_error, :request, :response
|
3
5
|
|
4
|
-
def initialize(original_error, request)
|
5
|
-
@original_error, @request = original_error, request
|
6
|
+
def initialize(original_error, request:, response:)
|
7
|
+
@original_error, @request, @response = original_error, request, response
|
6
8
|
end
|
7
9
|
|
8
10
|
def to_s
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
body = request.body
|
18
|
-
return request_info unless body
|
19
|
-
|
20
|
-
"#{request_info}#{body_info(parsed_body(body) || body)}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def parsed_body(body)
|
24
|
-
JSON.parse(body)
|
25
|
-
rescue StandardError
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def body_info(body)
|
30
|
-
body = parsed_body(body) || body
|
31
|
-
|
32
|
-
case body
|
33
|
-
when Hash
|
34
|
-
body.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")
|
35
|
-
else
|
36
|
-
body.inspect
|
37
|
-
end
|
11
|
+
parts = []
|
12
|
+
parts.push(original_error.to_s)
|
13
|
+
parts.push("=== #{request.method} #{request.path} =====================")
|
14
|
+
parts.push("> " + request.body.gsub("\n", "\n> ")) if request.body
|
15
|
+
parts.push("--- response ------------------------------------")
|
16
|
+
parts.push("< " + response.body.gsub("\n", "\n< ")) if response.body
|
17
|
+
parts.push("==================================================================")
|
18
|
+
parts.join("\n")
|
38
19
|
end
|
39
20
|
end
|
data/lib/rspec/httpd.rb
CHANGED
@@ -63,6 +63,8 @@ module RSpec::Httpd
|
|
63
63
|
expected = yield
|
64
64
|
end
|
65
65
|
|
66
|
+
expected = stringify_hash(expected) if expected.is_a?(Hash)
|
67
|
+
|
66
68
|
client ||= http
|
67
69
|
|
68
70
|
# only check status? This lets us write
|
@@ -83,8 +85,19 @@ module RSpec::Httpd
|
|
83
85
|
begin
|
84
86
|
# expect! comes from the expectation gem
|
85
87
|
expect! client.result => expected
|
86
|
-
rescue ::Expectation::Matcher::Mismatch
|
87
|
-
raise ExpectationFailed.new(
|
88
|
+
rescue ::Expectation::Matcher::Mismatch => e
|
89
|
+
raise ExpectationFailed.new(e, request: client.request, response: client.response), cause: nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def stringify_hash(hsh)
|
96
|
+
return unless hsh
|
97
|
+
|
98
|
+
hsh.inject({}) do |r, (k, v)|
|
99
|
+
k = k.to_s if k.is_a?(Symbol)
|
100
|
+
r.update k => v
|
88
101
|
end
|
89
102
|
end
|
90
103
|
end
|