hobby-test 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/lib/hobby/test.rb +38 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29df4b3baa9ab923470c3b0037484388ede86cd0
|
4
|
+
data.tar.gz: 561ceb2489957310e329a4bf001690d071b709e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b0f32b2ce5cb602dd25729282364035515fbf9cbe7ef3db66a7aad7e24203e09f5d489e81846c30d38043ac071b9ff2ffe2ca6272a7a3b292f0ac3178b7e5a6
|
7
|
+
data.tar.gz: f410b9a126e19e0413c2cbfd2eb9a7e3d9ae7ee5256a811a7d8b873dbd6410fdd4ec0ba4e8d56053377f104c6c92c34a580da43b28b3297fac3a827595126598
|
data/lib/hobby/test.rb
CHANGED
@@ -86,16 +86,25 @@ module Hobby
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
response, global_format = hash.values_at :response, :format
|
89
90
|
verb, params = hash.find &Key[Request::VERBS, :include?]
|
90
|
-
|
91
|
-
@
|
91
|
+
|
92
|
+
@response_format = response&.delete :format
|
93
|
+
|
94
|
+
@request = Request.new verb, params, global_format
|
95
|
+
@asserts = (response&.map &Assert) || []
|
92
96
|
end
|
93
97
|
|
94
98
|
def [] env
|
99
|
+
request_report = @request.perform_in env
|
100
|
+
|
101
|
+
response = env.last_response
|
102
|
+
response.format = @response_format if @response_format
|
103
|
+
|
95
104
|
Report.new \
|
96
|
-
request:
|
97
|
-
|
98
|
-
|
105
|
+
request: request_report,
|
106
|
+
response: response,
|
107
|
+
asserts: @asserts.map(&[env])
|
99
108
|
end
|
100
109
|
|
101
110
|
class Assert
|
@@ -189,9 +198,21 @@ module Hobby
|
|
189
198
|
|
190
199
|
class Request < OpenStruct
|
191
200
|
VERBS = %i[delete get head options patch post put]
|
192
|
-
def initialize
|
193
|
-
@verb
|
194
|
-
|
201
|
+
def initialize verb, params, format
|
202
|
+
@verb = verb
|
203
|
+
|
204
|
+
if local_format = params.delete('format')
|
205
|
+
@format = case local_format
|
206
|
+
when 'json' then JSON
|
207
|
+
when 'text' then nil
|
208
|
+
else
|
209
|
+
raise "Wrong format #{local_format}."
|
210
|
+
end
|
211
|
+
else
|
212
|
+
@format = format
|
213
|
+
end
|
214
|
+
|
215
|
+
super params
|
195
216
|
end
|
196
217
|
attr_reader :verb
|
197
218
|
|
@@ -246,6 +267,15 @@ module Hobby
|
|
246
267
|
end
|
247
268
|
attr_reader :format
|
248
269
|
|
270
|
+
def format= string
|
271
|
+
case string
|
272
|
+
when 'json' then JSON
|
273
|
+
when 'text' then nil
|
274
|
+
else
|
275
|
+
raise "Wrong format #{string}."
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
249
279
|
def body
|
250
280
|
@body ||= if format
|
251
281
|
format.load @excon_response.body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoly Chernow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|