rspec-rails-api 0.3.0 → 0.3.1

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: 74591eecb7e2b200f536ca31e72097ed9921da563a87490288f536edec32f728
4
- data.tar.gz: a5ec7199c37b2bf493eec385b3f294561acfa409c46dac9d744f1d7679a37f30
3
+ metadata.gz: 5c81756e5b64eb7e5d7363231a498c947377879806b92dac3d8f11c0d28fd7bb
4
+ data.tar.gz: 728634d884084a356b2f2d29ae410b6a54c70d47a8dfe9f0ac821bc75a80e160
5
5
  SHA512:
6
- metadata.gz: 4922b2a7257f432048f37cb9d73faf8b0b15a7750760429f3f29b657d282b5e556e9b380813843574d5be116ed040bd71a91ddb2301f0d65df6f38b70981204d
7
- data.tar.gz: b82d1c509e096f1ac04bebe56dbed7a4ed9e49a9de47b525cae0bba2355033ed61a727a17fb9691701f10dc0ba36be4c00a9b62531c2621b302910a25d200511
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 "-> #{status_code} - #{description}" do
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
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Rails
5
5
  module Api
6
- VERSION = '0.3.0'
6
+ VERSION = '0.3.1'
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.3.0
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: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport