rspec-httpd 0.0.10 → 0.0.11

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
  SHA256:
3
- metadata.gz: 63a83e63d887fb7d1a4624719c551449fed53ab9ce4fd737c23b81eca8fbfec9
4
- data.tar.gz: 85263b7c0017af759b76ae5f9c8f4b053775b570e741d006388b31075a16565f
3
+ metadata.gz: 7277e2b07cd04cb4c8a87062b2449244747ba07c032bfaf8b05d3d9b8e0a4761
4
+ data.tar.gz: c4974c0f457fbbd03c15d55d28408da3d1d6831509f5e56d7c1bb26dd80d2a10
5
5
  SHA512:
6
- metadata.gz: 97fc5313c1fb71e24622043efd4729bbd155ea4ae32057f5c92c705e3153d91b291156bdabe0780fcfa16804b18fcbf8f05eab802ccdd8a5addd6d961b0ab33e
7
- data.tar.gz: d74cb440e90cbc553d66351fab7739fc925e79104514444d998eee79e28ab7c18b69d685d7e4c2e40809c45749288388e86adc447337365f5d7a7415c0dea6d0
6
+ metadata.gz: 84eed9b38ea95f413ea42b981cb761b32b3e10885a5177fda369a4c2b14ba29ef130c4ad76fa4988c7ade0eecf7c2294f3599ac2cdeff7d1e3a7eec655fa3996
7
+ data.tar.gz: aeba7bb613f2664b801881377bbac3371eb75aae5a7c04a05f50ee9bb47cf69eea9e346e7f9b0c2d9ca8a6e0b10860cf93f3432be1188c38c5d33bed12eabe80
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
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
- "#{request_info}: #{original_error}"
10
- end
11
-
12
- private
13
-
14
- def request_info
15
- request_info = "#{request.method} #{request.path}"
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($!, client.request)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-httpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrico Thierbach