rspec-rails-api 0.1.0 → 0.1.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
  SHA256:
3
- metadata.gz: 0d84f33b2eb3f005afce4a2712e2fd3523687f5ba098573d93e386439aa97639
4
- data.tar.gz: e013cc905ed66797cd78c6d6c833c87ba30e939a0c12b950cb1209639789a3fd
3
+ metadata.gz: ae80a5b196a345ad25674bfae11ae466c979f216cca68912d205eb856c7096b9
4
+ data.tar.gz: 5201f1632652b2a46a2b436272497d7f0dc345b5710a8f218cfc0f80ac51241c
5
5
  SHA512:
6
- metadata.gz: 32a8012f525f7319555e5aada0b1019e37939461034522193e939a2a028a3fb5897a133e0fb5fdd93a4ef8b77d3a62d2092884bae9c6e3194e50da8b5bd3572d
7
- data.tar.gz: 5703b53a8d61d35c4e8124e615056da5c909bbe47e96fe9aeeb5362479a80db8d5c6999094ebb06d8502d1937f3520908d6554a66e3360ffb43d747c962d1021
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
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Rails
5
5
  module Api
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.2'
7
7
  end
8
8
  end
9
9
  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.0
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-21 00:00:00.000000000 Z
11
+ date: 2019-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport