rspec-rails-api 0.3.0 → 0.3.1
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 +11 -1
- data/lib/rspec/rails/api/dsl/example.rb +4 -2
- data/lib/rspec/rails/api/dsl/example_group.rb +3 -3
- 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: 5c81756e5b64eb7e5d7363231a498c947377879806b92dac3d8f11c0d28fd7bb
|
4
|
+
data.tar.gz: 728634d884084a356b2f2d29ae410b6a54c70d47a8dfe9f0ac821bc75a80e160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b50cb2972931d3a160bd2e3ab7ee73d73d4a762c7ee8e9264fae4903b3a98954d8d34aa6dc1aeecbd1fe40dea99cc6d02bd592e710a9a136b4665dd0285cd03
|
7
|
+
data.tar.gz: 482ab0880d61cf4b709034903a7509b57750bf121dcdab9acba7bc519ef4fd8e9c079f2b263d3c7732db18e8fbb6f333743ccd700ebe286fcb548ca3c1b8cbde
|
data/README.md
CHANGED
@@ -380,7 +380,7 @@ on_post '/api/items' do
|
|
380
380
|
end
|
381
381
|
```
|
382
382
|
|
383
|
-
##### `for_code(http_status, description = nil, doc_only: false &block)`
|
383
|
+
##### `for_code(http_status, description = nil, doc_only: false, test_only: false &block)`
|
384
384
|
|
385
385
|
Describes the desired output for a precedently defined URL.
|
386
386
|
|
@@ -388,6 +388,9 @@ Block takes one required argument, that should be passed to `visit`.
|
|
388
388
|
This argument will contain the block context and allow `visit` to access
|
389
389
|
the metadatas.
|
390
390
|
|
391
|
+
You can have only one documented code per action/url, unless you use
|
392
|
+
`test_only`.
|
393
|
+
|
391
394
|
- `http_status` is an integer representing an
|
392
395
|
[HTTP status](https://httpstat.us/)
|
393
396
|
- `description` should be some valid
|
@@ -395,6 +398,8 @@ the metadatas.
|
|
395
398
|
translation of the `http_status` will be used.
|
396
399
|
- `doc_only` can be set to true to temporarily disable block execution
|
397
400
|
and only create the documentation (without examples).
|
401
|
+
- `test_only` will omit the test from the documentation. Useful when you
|
402
|
+
need to test things _around_ the call (response content, db,...)
|
398
403
|
- `block` where additional tests can be performed. If `visit()` is
|
399
404
|
called within the block, its output will be used in documentation
|
400
405
|
examples, and the response type and code will actually be tested.
|
@@ -412,6 +417,11 @@ Once again, you have to pass an argument to the block if you use
|
|
412
417
|
visit url
|
413
418
|
# ...
|
414
419
|
end
|
420
|
+
|
421
|
+
for_code 200, 'Side test', test_only: true do |url|
|
422
|
+
visit url
|
423
|
+
# ...
|
424
|
+
end
|
415
425
|
# ...
|
416
426
|
```
|
417
427
|
|
@@ -6,7 +6,7 @@ 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: {}, headers: {}) # rubocop:disable Metrics/AbcSize
|
9
|
+
def visit(example, path_params: {}, payload: {}, headers: {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
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
|
@@ -21,6 +21,8 @@ module RSpec
|
|
21
21
|
|
22
22
|
check_response(response, status_code)
|
23
23
|
|
24
|
+
return if example.class.description.match?(/-> test (\d+)(.*)/)
|
25
|
+
|
24
26
|
set_request_example example.class.metadata[:rrad], request_params, status_code, response.body
|
25
27
|
end
|
26
28
|
|
@@ -86,7 +88,7 @@ module RSpec
|
|
86
88
|
end
|
87
89
|
|
88
90
|
def prepare_status_code(description)
|
89
|
-
code_match = /-> (\d+) - .*/.match description
|
91
|
+
code_match = /->(?: test)? (\d+) - .*/.match description
|
90
92
|
|
91
93
|
raise 'Please provide a numerical code for the "for_code" block' unless code_match
|
92
94
|
|
@@ -74,12 +74,12 @@ module RSpec
|
|
74
74
|
describe("#{action.upcase} #{url}", &block)
|
75
75
|
end
|
76
76
|
|
77
|
-
def for_code(status_code, description = nil, doc_only: false, &block)
|
77
|
+
def for_code(status_code, description = nil, doc_only: false, test_only: false, &block)
|
78
78
|
description ||= Rack::Utils::HTTP_STATUS_CODES[status_code]
|
79
79
|
|
80
|
-
metadata[:rrad].add_status_code(status_code, description)
|
80
|
+
metadata[:rrad].add_status_code(status_code, description) unless test_only
|
81
81
|
|
82
|
-
describe "
|
82
|
+
describe "->#{test_only ? ' test' : ''} #{status_code} - #{description}" do
|
83
83
|
execute_for_code_block(status_code, doc_only, block)
|
84
84
|
end
|
85
85
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Tancoigne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|