rspec-rails-api 0.1.0 → 0.1.2
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 +4 -4
- data/README.md +6 -10
- data/lib/rspec/rails/api/dsl/example.rb +6 -6
- data/lib/rspec/rails/api/metadata.rb +4 -1
- data/lib/rspec/rails/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae80a5b196a345ad25674bfae11ae466c979f216cca68912d205eb856c7096b9
|
4
|
+
data.tar.gz: 5201f1632652b2a46a2b436272497d7f0dc345b5710a8f218cfc0f80ac51241c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e87c17a14f52fbec2b85e5c37d0b3c20b6059a0d5592bf10d11bc092be10cb4cb183446328bd1fd1f6b766cd145516a1ce83965d3e6915e530d4dfc01e86c0
|
7
|
+
data.tar.gz: 8ce1bd90eb8c0c99ca561fa2410b41eb0d9492414283e926e9c60143b970a9a23b5e1abdb82e99d5f0be6b9647a0444502a5778560abb12a83f82aad205ba3a4
|
data/README.md
CHANGED
@@ -310,7 +310,7 @@ Once again, you have to pass an argument to the block if you use
|
|
310
310
|
|
311
311
|
Example methods are available in `for_code` blocks
|
312
312
|
|
313
|
-
##### `visit(example, path_params: {}, payload: {})`
|
313
|
+
##### `visit(example, path_params: {}, payload: {}, headers: {})`
|
314
314
|
|
315
315
|
Visits the described URL and:
|
316
316
|
|
@@ -323,6 +323,7 @@ Visits the described URL and:
|
|
323
323
|
value is needed)
|
324
324
|
- `payload`: a hash of values to send. Ignored for GET and DELETE
|
325
325
|
requests
|
326
|
+
- `headers`: a hash of custom headers.
|
326
327
|
|
327
328
|
```rb
|
328
329
|
for_code 200, 'Success' do |example|
|
@@ -342,8 +343,8 @@ It should be compared against a hash or a `response` object:
|
|
342
343
|
```rb
|
343
344
|
#...
|
344
345
|
entity user:
|
345
|
-
id: { type: :integer, desc: 'The id',
|
346
|
-
name: { type: :string, desc: 'The name'
|
346
|
+
id: { type: :integer, desc: 'The id' },
|
347
|
+
name: { type: :string, desc: 'The name' }
|
347
348
|
|
348
349
|
#...
|
349
350
|
|
@@ -365,8 +366,8 @@ It should be compared against an array or a `response` object:
|
|
365
366
|
```rb
|
366
367
|
#...
|
367
368
|
entity user:
|
368
|
-
id: { type: :integer, desc: 'The id',
|
369
|
-
name: { type: :string, desc: 'The name'
|
369
|
+
id: { type: :integer, desc: 'The id' },
|
370
|
+
name: { type: :string, desc: 'The name }'
|
370
371
|
|
371
372
|
#...
|
372
373
|
|
@@ -416,11 +417,6 @@ attributes of an `has_many` relation)
|
|
416
417
|
|
417
418
|
MRs to improve this are welcome.
|
418
419
|
|
419
|
-
### Headers
|
420
|
-
|
421
|
-
There is no way to have custom headers yet. This means, no token-based
|
422
|
-
auth.
|
423
|
-
|
424
420
|
### Files
|
425
421
|
|
426
422
|
There is no support for file fields yet.
|
@@ -6,11 +6,11 @@ module RSpec
|
|
6
6
|
module DSL
|
7
7
|
# These methods will be available in examples (i.e.: 'for_code')
|
8
8
|
module Example
|
9
|
-
def visit(example, path_params: {}, payload: {}) # rubocop:disable Metrics/AbcSize
|
9
|
+
def visit(example, path_params: {}, payload: {}, headers: {}) # rubocop:disable Metrics/AbcSize
|
10
10
|
raise 'Missing context. Call visit with for_code context.' unless example
|
11
11
|
|
12
12
|
status_code = prepare_status_code example.class.description
|
13
|
-
request_params = prepare_request_params example.class.parent.description, path_params, payload
|
13
|
+
request_params = prepare_request_params example.class.parent.description, path_params, payload, headers
|
14
14
|
|
15
15
|
send(request_params[:action],
|
16
16
|
request_params[:url],
|
@@ -50,7 +50,7 @@ module RSpec
|
|
50
50
|
params: request_params[:params])
|
51
51
|
end
|
52
52
|
|
53
|
-
def prepare_request_params(description, request_params = {}, payload = {})
|
53
|
+
def prepare_request_params(description, request_params = {}, payload = {}, request_headers = {})
|
54
54
|
example_params = description.split ' '
|
55
55
|
|
56
56
|
{
|
@@ -58,7 +58,7 @@ module RSpec
|
|
58
58
|
url: prepare_request_url(example_params[1], request_params),
|
59
59
|
example_url: example_params[1],
|
60
60
|
params: payload,
|
61
|
-
headers: prepare_request_headers,
|
61
|
+
headers: prepare_request_headers(request_headers),
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
@@ -76,11 +76,11 @@ module RSpec
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def prepare_request_headers
|
79
|
+
def prepare_request_headers(headers = {})
|
80
80
|
{
|
81
81
|
'Accept' => 'application/json',
|
82
82
|
'Content-Type' => 'application/json',
|
83
|
-
}
|
83
|
+
}.merge headers
|
84
84
|
end
|
85
85
|
|
86
86
|
def prepare_status_code(description)
|
@@ -166,10 +166,13 @@ module RSpec
|
|
166
166
|
if field[:type] && field[:type] == :object
|
167
167
|
organize_params field[:properties] if field[:properties]
|
168
168
|
else
|
169
|
-
{
|
169
|
+
properties = {
|
170
170
|
type: field[:type].to_s,
|
171
171
|
description: field[:description] || nil,
|
172
172
|
}
|
173
|
+
|
174
|
+
properties[:items] = {} if field[:type] == :array
|
175
|
+
properties
|
173
176
|
end
|
174
177
|
end
|
175
178
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Tancoigne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|