rspec-apib 0.3.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.envrc +1 -1
- data/.github/workflows/main.yaml +64 -0
- data/.gitignore +0 -1
- data/.ruby-version +1 -1
- data/.travis.yml +12 -2
- data/Dockerfile +1 -1
- data/Gemfile.lock +204 -0
- data/README.md +64 -9
- data/lib/rspec/apib/comments_parser.rb +60 -0
- data/lib/rspec/apib/configuration.rb +2 -1
- data/lib/rspec/apib/recorder.rb +6 -30
- data/lib/rspec/apib/version.rb +1 -1
- data/lib/rspec/apib/writer.rb +6 -1
- data/lib/rspec/apib.rb +11 -3
- data/rspec-apib.gemspec +6 -6
- metadata +43 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 26808709aea326712fc538ae00846a5004584e5c381b1bce4b651a0d3af5e5aa
|
4
|
+
data.tar.gz: 7f6a4e287c88410a387d07c5ea4724ac0b90f092cf215251f305492ebbbab6a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86ec2a27b570442fca01a9ed68091773fc6a27673005e20b2b39c79fe5d3e614bda7bb81f83c1dc09af7d4e463c5f746a23a2a51adf01361f9312a02f76cc635
|
7
|
+
data.tar.gz: a78ef6411fc0cf064d153d168b6268642f69939c07338400591fb14ac63e302660ba0e5eba48d0d4ed60f3681ab151e46acec008e43b184f78346779ac76572d
|
data/.envrc
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
name: Main
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
env:
|
10
|
+
RAILS_ENV: test
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.7
|
19
|
+
|
20
|
+
- name: Run tests (rails5, rspec3)
|
21
|
+
env:
|
22
|
+
RAILS_VERSION: '~> 5.0'
|
23
|
+
RSPEC_VERSION: '~> 3.0'
|
24
|
+
run: |
|
25
|
+
gem install bundler -v 1
|
26
|
+
rm Gemfile.lock
|
27
|
+
bundle install
|
28
|
+
bundle exec rspec
|
29
|
+
|
30
|
+
- name: Run tests (rails6, rspec3)
|
31
|
+
env:
|
32
|
+
RAILS_VERSION: '~> 6.0'
|
33
|
+
RSPEC_VERSION: '~> 3.0'
|
34
|
+
run: |
|
35
|
+
gem install bundler -v 1
|
36
|
+
rm Gemfile.lock
|
37
|
+
bundle install
|
38
|
+
bundle exec rspec
|
39
|
+
|
40
|
+
- name: Run tests (rails5, rspec4)
|
41
|
+
env:
|
42
|
+
RAILS_VERSION: '~> 5.0'
|
43
|
+
RSPEC_VERSION: '~> 4.0'
|
44
|
+
run: |
|
45
|
+
gem install bundler -v 1
|
46
|
+
rm Gemfile.lock
|
47
|
+
bundle install
|
48
|
+
bundle exec rspec
|
49
|
+
|
50
|
+
- name: Run tests (rails6, rspec4)
|
51
|
+
env:
|
52
|
+
RAILS_VERSION: '~> 6.0'
|
53
|
+
RSPEC_VERSION: '~> 4.0'
|
54
|
+
run: |
|
55
|
+
gem install bundler -v 1
|
56
|
+
rm Gemfile.lock
|
57
|
+
bundle install
|
58
|
+
bundle exec rspec
|
59
|
+
|
60
|
+
- name: Run tests (as locked)
|
61
|
+
run: |
|
62
|
+
gem install bundler -v 1
|
63
|
+
bundle install
|
64
|
+
bundle exec rspec
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2
|
1
|
+
2.7.2
|
data/.travis.yml
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
|
3
|
+
- 2.5
|
4
|
+
env:
|
5
|
+
- NO_LOCK=false
|
6
|
+
- NO_LOCK=true RAILS_VERSION='~> 4.0' RSPEC_VERSION='~> 3.0'
|
7
|
+
- NO_LOCK=true RAILS_VERSION='~> 5.0' RSPEC_VERSION='~> 3.0'
|
8
|
+
- NO_LOCK=true RAILS_VERSION='~> 6.0' RSPEC_VERSION='~> 3.0'
|
9
|
+
- NO_LOCK=true RAILS_VERSION='~> 4.0' RSPEC_VERSION='~> 4.0'
|
10
|
+
- NO_LOCK=true RAILS_VERSION='~> 5.0' RSPEC_VERSION='~> 4.0'
|
11
|
+
- NO_LOCK=true RAILS_VERSION='~> 6.0' RSPEC_VERSION='~> 4.0'
|
12
|
+
before_install:
|
13
|
+
- gem install bundler -v 1
|
14
|
+
- $NO_LOCK && rm Gemfile.lock || true
|
data/Dockerfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-apib (1.0.0)
|
5
|
+
rails (>= 6.0.0)
|
6
|
+
rspec-rails (~> 4.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (6.1.4)
|
12
|
+
actionpack (= 6.1.4)
|
13
|
+
activesupport (= 6.1.4)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (6.1.4)
|
17
|
+
actionpack (= 6.1.4)
|
18
|
+
activejob (= 6.1.4)
|
19
|
+
activerecord (= 6.1.4)
|
20
|
+
activestorage (= 6.1.4)
|
21
|
+
activesupport (= 6.1.4)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.1.4)
|
24
|
+
actionpack (= 6.1.4)
|
25
|
+
actionview (= 6.1.4)
|
26
|
+
activejob (= 6.1.4)
|
27
|
+
activesupport (= 6.1.4)
|
28
|
+
mail (~> 2.5, >= 2.5.4)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
actionpack (6.1.4)
|
31
|
+
actionview (= 6.1.4)
|
32
|
+
activesupport (= 6.1.4)
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
34
|
+
rack-test (>= 0.6.3)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
+
actiontext (6.1.4)
|
38
|
+
actionpack (= 6.1.4)
|
39
|
+
activerecord (= 6.1.4)
|
40
|
+
activestorage (= 6.1.4)
|
41
|
+
activesupport (= 6.1.4)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (6.1.4)
|
44
|
+
activesupport (= 6.1.4)
|
45
|
+
builder (~> 3.1)
|
46
|
+
erubi (~> 1.4)
|
47
|
+
rails-dom-testing (~> 2.0)
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (6.1.4)
|
50
|
+
activesupport (= 6.1.4)
|
51
|
+
globalid (>= 0.3.6)
|
52
|
+
activemodel (6.1.4)
|
53
|
+
activesupport (= 6.1.4)
|
54
|
+
activerecord (6.1.4)
|
55
|
+
activemodel (= 6.1.4)
|
56
|
+
activesupport (= 6.1.4)
|
57
|
+
activestorage (6.1.4)
|
58
|
+
actionpack (= 6.1.4)
|
59
|
+
activejob (= 6.1.4)
|
60
|
+
activerecord (= 6.1.4)
|
61
|
+
activesupport (= 6.1.4)
|
62
|
+
marcel (~> 1.0.0)
|
63
|
+
mini_mime (>= 1.1.0)
|
64
|
+
activesupport (6.1.4)
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
zeitwerk (~> 2.3)
|
70
|
+
builder (3.2.4)
|
71
|
+
coderay (1.1.2)
|
72
|
+
concurrent-ruby (1.1.9)
|
73
|
+
crass (1.0.6)
|
74
|
+
diff-lcs (1.4.4)
|
75
|
+
erubi (1.10.0)
|
76
|
+
ffi (1.12.2)
|
77
|
+
formatador (0.2.5)
|
78
|
+
globalid (0.5.2)
|
79
|
+
activesupport (>= 5.0)
|
80
|
+
guard (2.16.2)
|
81
|
+
formatador (>= 0.2.4)
|
82
|
+
listen (>= 2.7, < 4.0)
|
83
|
+
lumberjack (>= 1.0.12, < 2.0)
|
84
|
+
nenv (~> 0.1)
|
85
|
+
notiffany (~> 0.0)
|
86
|
+
pry (>= 0.9.12)
|
87
|
+
shellany (~> 0.0)
|
88
|
+
thor (>= 0.18.1)
|
89
|
+
guard-compat (1.2.1)
|
90
|
+
guard-rspec (4.7.3)
|
91
|
+
guard (~> 2.1)
|
92
|
+
guard-compat (~> 1.1)
|
93
|
+
rspec (>= 2.99.0, < 4.0)
|
94
|
+
i18n (1.8.10)
|
95
|
+
concurrent-ruby (~> 1.0)
|
96
|
+
listen (3.2.1)
|
97
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
98
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
99
|
+
loofah (2.12.0)
|
100
|
+
crass (~> 1.0.2)
|
101
|
+
nokogiri (>= 1.5.9)
|
102
|
+
lumberjack (1.0.13)
|
103
|
+
mail (2.7.1)
|
104
|
+
mini_mime (>= 0.1.1)
|
105
|
+
marcel (1.0.1)
|
106
|
+
method_source (1.0.0)
|
107
|
+
mini_mime (1.1.0)
|
108
|
+
mini_portile2 (2.6.1)
|
109
|
+
minitest (5.14.4)
|
110
|
+
nenv (0.3.0)
|
111
|
+
nio4r (2.5.8)
|
112
|
+
nokogiri (1.12.3)
|
113
|
+
mini_portile2 (~> 2.6.1)
|
114
|
+
racc (~> 1.4)
|
115
|
+
notiffany (0.1.3)
|
116
|
+
nenv (~> 0.1)
|
117
|
+
shellany (~> 0.0)
|
118
|
+
pry (0.13.1)
|
119
|
+
coderay (~> 1.1)
|
120
|
+
method_source (~> 1.0)
|
121
|
+
racc (1.5.2)
|
122
|
+
rack (2.2.3)
|
123
|
+
rack-test (1.1.0)
|
124
|
+
rack (>= 1.0, < 3)
|
125
|
+
rails (6.1.4)
|
126
|
+
actioncable (= 6.1.4)
|
127
|
+
actionmailbox (= 6.1.4)
|
128
|
+
actionmailer (= 6.1.4)
|
129
|
+
actionpack (= 6.1.4)
|
130
|
+
actiontext (= 6.1.4)
|
131
|
+
actionview (= 6.1.4)
|
132
|
+
activejob (= 6.1.4)
|
133
|
+
activemodel (= 6.1.4)
|
134
|
+
activerecord (= 6.1.4)
|
135
|
+
activestorage (= 6.1.4)
|
136
|
+
activesupport (= 6.1.4)
|
137
|
+
bundler (>= 1.15.0)
|
138
|
+
railties (= 6.1.4)
|
139
|
+
sprockets-rails (>= 2.0.0)
|
140
|
+
rails-dom-testing (2.0.3)
|
141
|
+
activesupport (>= 4.2.0)
|
142
|
+
nokogiri (>= 1.6)
|
143
|
+
rails-html-sanitizer (1.3.0)
|
144
|
+
loofah (~> 2.3)
|
145
|
+
railties (6.1.4)
|
146
|
+
actionpack (= 6.1.4)
|
147
|
+
activesupport (= 6.1.4)
|
148
|
+
method_source
|
149
|
+
rake (>= 0.13)
|
150
|
+
thor (~> 1.0)
|
151
|
+
rake (13.0.6)
|
152
|
+
rb-fsevent (0.10.4)
|
153
|
+
rb-inotify (0.10.1)
|
154
|
+
ffi (~> 1.0)
|
155
|
+
rspec (3.9.0)
|
156
|
+
rspec-core (~> 3.9.0)
|
157
|
+
rspec-expectations (~> 3.9.0)
|
158
|
+
rspec-mocks (~> 3.9.0)
|
159
|
+
rspec-core (3.9.3)
|
160
|
+
rspec-support (~> 3.9.3)
|
161
|
+
rspec-expectations (3.9.4)
|
162
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
163
|
+
rspec-support (~> 3.9.0)
|
164
|
+
rspec-mocks (3.9.1)
|
165
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
166
|
+
rspec-support (~> 3.9.0)
|
167
|
+
rspec-rails (4.0.1)
|
168
|
+
actionpack (>= 4.2)
|
169
|
+
activesupport (>= 4.2)
|
170
|
+
railties (>= 4.2)
|
171
|
+
rspec-core (~> 3.9)
|
172
|
+
rspec-expectations (~> 3.9)
|
173
|
+
rspec-mocks (~> 3.9)
|
174
|
+
rspec-support (~> 3.9)
|
175
|
+
rspec-support (3.9.4)
|
176
|
+
shellany (0.0.1)
|
177
|
+
sprockets (4.0.2)
|
178
|
+
concurrent-ruby (~> 1.0)
|
179
|
+
rack (> 1, < 3)
|
180
|
+
sprockets-rails (3.2.2)
|
181
|
+
actionpack (>= 4.0)
|
182
|
+
activesupport (>= 4.0)
|
183
|
+
sprockets (>= 3.0.0)
|
184
|
+
thor (1.1.0)
|
185
|
+
tzinfo (2.0.4)
|
186
|
+
concurrent-ruby (~> 1.0)
|
187
|
+
websocket-driver (0.7.5)
|
188
|
+
websocket-extensions (>= 0.1.0)
|
189
|
+
websocket-extensions (0.1.5)
|
190
|
+
zeitwerk (2.4.2)
|
191
|
+
|
192
|
+
PLATFORMS
|
193
|
+
ruby
|
194
|
+
|
195
|
+
DEPENDENCIES
|
196
|
+
bundler (>= 2.2.11)
|
197
|
+
guard (~> 2.16.2)
|
198
|
+
guard-rspec (~> 4.7.3)
|
199
|
+
pry
|
200
|
+
rake (>= 13.0.6)
|
201
|
+
rspec-apib!
|
202
|
+
|
203
|
+
BUNDLED WITH
|
204
|
+
2.2.11
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Rspec::Apib
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
This is meant to be a drop-in solution for generating an API documentation from
|
4
|
+
existing RSpec request specs. The result is not always perfect, but hopefully
|
5
|
+
gives your developers and/or customers an idea of how your API works.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -40,6 +40,14 @@ RSpec::Apib.configure do |config|
|
|
40
40
|
|
41
41
|
# Example types to record
|
42
42
|
config.record_types = [:request]
|
43
|
+
|
44
|
+
# Recording policy
|
45
|
+
|
46
|
+
# The default recording policy is `true`. This results in a recording of
|
47
|
+
# all matching specs. By changing this policy to `false`, you can selectively
|
48
|
+
# include certain specs by adding `apib: true` to your example options.
|
49
|
+
#
|
50
|
+
# config.default_recording_policy = false
|
43
51
|
end
|
44
52
|
# ...
|
45
53
|
RSpec::Apib.start
|
@@ -51,18 +59,65 @@ By default, request specs get recorded and written to a `.apib` file afterwards.
|
|
51
59
|
Rspec-apib is trying to make sense of the test run and generates a meaningful
|
52
60
|
documentation out of it.
|
53
61
|
|
54
|
-
|
62
|
+
- **Disable single examples:** Add `apib: false` to the examples meta data
|
63
|
+
|
55
64
|
```ruby
|
56
65
|
it 'does something', apib: false do
|
57
66
|
# ...
|
58
67
|
end
|
59
68
|
```
|
60
69
|
|
61
|
-
|
62
|
-
|
70
|
+
- **Custom example description:** Add an _apib_ comment above the example
|
71
|
+
You can add a description for the request, response or both.
|
72
|
+
|
73
|
+
Description only for the request
|
74
|
+
|
75
|
+
````ruby
|
76
|
+
# Not contained in the description
|
77
|
+
#
|
78
|
+
# --- apib:request
|
79
|
+
# Some awesome description of the request
|
80
|
+
#
|
81
|
+
# ```json
|
82
|
+
# {}
|
83
|
+
# ```
|
84
|
+
# ---
|
85
|
+
#
|
86
|
+
# Not contained in the description
|
87
|
+
#
|
88
|
+
it 'has a custom description' do
|
89
|
+
# ...
|
90
|
+
end
|
91
|
+
````
|
92
|
+
|
93
|
+
Description only for the response
|
94
|
+
|
95
|
+
````ruby
|
96
|
+
# Not contained in the description
|
97
|
+
# -- apib:response
|
98
|
+
# Some awesome description of the response
|
99
|
+
#
|
100
|
+
# ```json
|
101
|
+
# {}
|
102
|
+
# ```
|
103
|
+
# ---
|
104
|
+
#
|
105
|
+
# Not contained in the description
|
106
|
+
#
|
107
|
+
it 'has a custom description' do
|
108
|
+
# ...
|
109
|
+
end
|
110
|
+
````
|
111
|
+
|
112
|
+
Description for both request and response
|
113
|
+
|
114
|
+
````ruby
|
63
115
|
# Not contained in the description
|
64
116
|
#
|
65
|
-
# --- apib
|
117
|
+
# --- apib:request
|
118
|
+
# Some awesome description of the request
|
119
|
+
#
|
120
|
+
# -- apib:response
|
66
121
|
# Some awesome description of the response
|
67
122
|
#
|
68
123
|
# ```json
|
@@ -75,7 +130,7 @@ documentation out of it.
|
|
75
130
|
it 'has a custom description' do
|
76
131
|
# ...
|
77
132
|
end
|
78
|
-
|
133
|
+
````
|
79
134
|
|
80
135
|
## Development
|
81
136
|
|
@@ -88,7 +143,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
88
143
|
To do continuous testing during development `guard` can be used. In order to
|
89
144
|
test against multiple versions of Rails, the environment variable
|
90
145
|
`RAILS_VERSION` can be used to choose a different dependency pattern then the
|
91
|
-
default one specified in the
|
146
|
+
default one specified in the _.gemspec_ file.
|
92
147
|
|
93
148
|
```
|
94
149
|
RAILS_VERSION='~> 4.0' bundle install; bundle exec rspec
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Apib
|
3
|
+
class CommentsParser
|
4
|
+
attr_reader :example
|
5
|
+
|
6
|
+
def initialize(example)
|
7
|
+
@example = example
|
8
|
+
end
|
9
|
+
|
10
|
+
def full_comment
|
11
|
+
line = example.metadata[:line_number]
|
12
|
+
return if line.nil? || line <= 0
|
13
|
+
|
14
|
+
lines = read_example_file
|
15
|
+
return if lines.count < line
|
16
|
+
|
17
|
+
i = line -2
|
18
|
+
result = []
|
19
|
+
|
20
|
+
while (i >= 0 && match = lines[i].match(/\A\s*#\s(.*)/)) do
|
21
|
+
result.unshift(match[1])
|
22
|
+
i -= 1
|
23
|
+
end
|
24
|
+
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def description(namespace = nil)
|
29
|
+
matcher = start_matcher(namespace)
|
30
|
+
comment = full_comment()
|
31
|
+
in_comment = false
|
32
|
+
return nil if comment.blank?
|
33
|
+
|
34
|
+
comment.select do |elem|
|
35
|
+
if elem == matcher
|
36
|
+
in_comment = true
|
37
|
+
elsif elem.match?(/\A---($|[^-])/)
|
38
|
+
in_comment = false
|
39
|
+
end
|
40
|
+
|
41
|
+
in_comment && elem != matcher
|
42
|
+
end.join("\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def read_example_file
|
48
|
+
file = example.metadata[:absolute_file_path]
|
49
|
+
return [] if file.nil? || file.empty?
|
50
|
+
return [] unless File.exists?(file)
|
51
|
+
IO.readlines(file)
|
52
|
+
end
|
53
|
+
|
54
|
+
def start_matcher(namespace)
|
55
|
+
return "--- apib" if namespace.blank?
|
56
|
+
"--- apib:#{namespace}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -2,7 +2,7 @@ module RSpec
|
|
2
2
|
module Apib
|
3
3
|
class Configuration < Struct.new(
|
4
4
|
:dest_file, :pre_docs, :post_docs, :request_header_blacklist,
|
5
|
-
:request_param_blacklist, :record_types
|
5
|
+
:request_param_blacklist, :record_types, :default_recording_policy
|
6
6
|
)
|
7
7
|
def initialize
|
8
8
|
self.pre_docs = []
|
@@ -10,6 +10,7 @@ module RSpec
|
|
10
10
|
self.request_header_blacklist = %w(host accept cookie)
|
11
11
|
self.request_param_blacklist = %i(controller action)
|
12
12
|
self.record_types = %i(request)
|
13
|
+
self.default_recording_policy = true
|
13
14
|
end
|
14
15
|
|
15
16
|
def dest_file
|
data/lib/rspec/apib/recorder.rb
CHANGED
@@ -19,6 +19,10 @@ module RSpec
|
|
19
19
|
document_response
|
20
20
|
end
|
21
21
|
|
22
|
+
def comments_parser
|
23
|
+
@comments_parser ||= CommentsParser.new(example)
|
24
|
+
end
|
25
|
+
|
22
26
|
private
|
23
27
|
|
24
28
|
# Request headers contained in the blacklist will not be included in the
|
@@ -102,6 +106,7 @@ module RSpec
|
|
102
106
|
def document_request
|
103
107
|
document_request_params
|
104
108
|
return if response.status >= action[:request][:_status]
|
109
|
+
action[:request][:description] = comments_parser.description("request")
|
105
110
|
action[:request][:_status] = response.status
|
106
111
|
action[:request][:path] = request.path
|
107
112
|
action[:request][:body] = request.body.read
|
@@ -136,7 +141,7 @@ module RSpec
|
|
136
141
|
def document_response
|
137
142
|
data = {}
|
138
143
|
return if response_exists?
|
139
|
-
data[:description] =
|
144
|
+
data[:description] = comments_parser.description("response") || example.description
|
140
145
|
data[:status] = response.status
|
141
146
|
data[:content_type] = response.content_type.to_s
|
142
147
|
data[:body] = response.body
|
@@ -144,35 +149,6 @@ module RSpec
|
|
144
149
|
action[:response] << data
|
145
150
|
end
|
146
151
|
|
147
|
-
def document_extended_description
|
148
|
-
file = example.metadata[:absolute_file_path]
|
149
|
-
line = example.metadata[:line_number]
|
150
|
-
return if file.nil? || file.empty?
|
151
|
-
return if line.nil? || line <= 0
|
152
|
-
return unless File.exists?(file)
|
153
|
-
lines = IO.readlines(file)
|
154
|
-
return if lines.count < line
|
155
|
-
i = line -2
|
156
|
-
m = false
|
157
|
-
while (i >= 0 && lines[i].match(/\A\s*#/)) do
|
158
|
-
if lines[i - 1].match(/\A\s*# --- apib/)
|
159
|
-
m = true
|
160
|
-
break
|
161
|
-
end
|
162
|
-
i -= 1
|
163
|
-
end
|
164
|
-
return unless m
|
165
|
-
result = []
|
166
|
-
while (i < line && lines[i].match(/\A\s*#/)) do
|
167
|
-
if lines[i].match(/\A\s*# ---\s*\z/)
|
168
|
-
break
|
169
|
-
end
|
170
|
-
result << lines[i].sub(/^\s*#( |)/, '').rstrip
|
171
|
-
i += 1
|
172
|
-
end
|
173
|
-
return result.join("\n")
|
174
|
-
end
|
175
|
-
|
176
152
|
def response_exists?
|
177
153
|
action[:response].any? { |r| r[:status] == response.status }
|
178
154
|
end
|
data/lib/rspec/apib/version.rb
CHANGED
data/lib/rspec/apib/writer.rb
CHANGED
@@ -29,10 +29,14 @@ module RSpec
|
|
29
29
|
RSpec::Apib.config.post_docs.map { |f| File.read(f) }.join("\n\n")
|
30
30
|
end
|
31
31
|
|
32
|
+
def sorted_apib
|
33
|
+
@apib.to_a.sort { |a, b| a[0] <=> b[0] }
|
34
|
+
end
|
35
|
+
|
32
36
|
def build
|
33
37
|
apib = ""
|
34
38
|
|
35
|
-
|
39
|
+
sorted_apib.each do |group_name, group|
|
36
40
|
apib += "# Group #{group_name}\n\n"
|
37
41
|
group.each do |action, data|
|
38
42
|
apib += "## #{action}\n\n"
|
@@ -48,6 +52,7 @@ module RSpec
|
|
48
52
|
end
|
49
53
|
|
50
54
|
apib += "+ Request\n\n"
|
55
|
+
apib += "#{data[:request][:description].indent(2, ' ')}\n\n" if data[:request][:description]
|
51
56
|
apib += " + Headers\n\n"
|
52
57
|
data[:request][:headers].each do |header, value|
|
53
58
|
apib += " #{header}: #{value}\n"
|
data/lib/rspec/apib.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'rspec/apib/version'
|
3
3
|
require 'rspec/apib/configuration'
|
4
|
+
require 'rspec/apib/comments_parser'
|
4
5
|
require 'rspec/apib/recorder'
|
5
6
|
require 'rspec/apib/writer'
|
6
7
|
|
@@ -22,11 +23,9 @@ module RSpec
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def start
|
25
|
-
types = config.record_types
|
26
26
|
RSpec.configure do |config|
|
27
27
|
config.after :each do |example|
|
28
|
-
if
|
29
|
-
!(example.metadata[:apib] === false)
|
28
|
+
if RSpec::Apib.record?(example)
|
30
29
|
RSpec::Apib.record(example, request, response, @routes)
|
31
30
|
end
|
32
31
|
end
|
@@ -47,6 +46,15 @@ module RSpec
|
|
47
46
|
writer = Writer.new(@_doc || {})
|
48
47
|
writer.write
|
49
48
|
end
|
49
|
+
|
50
|
+
def record?(example)
|
51
|
+
default_recording_policy = config.default_recording_policy
|
52
|
+
config.record_types.include?(example.metadata[:type]) &&
|
53
|
+
(
|
54
|
+
default_recording_policy && !(example.metadata[:apib] === false) ||
|
55
|
+
!default_recording_policy && (example.metadata[:apib] === true)
|
56
|
+
)
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
data/rspec-apib.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '
|
22
|
-
spec.add_development_dependency 'rake', '
|
23
|
-
spec.add_development_dependency 'guard', '~> 2.
|
24
|
-
spec.add_development_dependency 'guard-rspec', '~> 4.
|
21
|
+
spec.add_development_dependency 'bundler', '>= 2.2.11'
|
22
|
+
spec.add_development_dependency 'rake', '>= 13.0.6'
|
23
|
+
spec.add_development_dependency 'guard', '~> 2.16.2'
|
24
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7.3'
|
25
25
|
spec.add_development_dependency 'pry'
|
26
|
-
spec.add_dependency 'rails', (ENV['RAILS_VERSION'] || '>=
|
27
|
-
spec.add_dependency 'rspec-rails', '~>
|
26
|
+
spec.add_dependency 'rails', (ENV['RAILS_VERSION'] || '>= 6.0.0')
|
27
|
+
spec.add_dependency 'rspec-rails', (ENV['RSPEC_VERSION'] || '~> 4.0')
|
28
28
|
end
|
metadata
CHANGED
@@ -1,113 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-apib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Spieker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.11
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 13.0.6
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 13.0.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 2.16.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.16.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 4.
|
61
|
+
version: 4.7.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 4.
|
68
|
+
version: 4.7.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 6.0.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 6.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '4.0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '4.0'
|
111
111
|
description:
|
112
112
|
email:
|
113
113
|
- p.spieker@duenos.de
|
@@ -115,18 +115,20 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .codeclimate.yml
|
119
|
-
- .dockerignore
|
120
|
-
- .envrc
|
121
|
-
- .
|
122
|
-
- .
|
123
|
-
- .
|
124
|
-
- .
|
125
|
-
- .ruby-
|
126
|
-
- .
|
118
|
+
- ".codeclimate.yml"
|
119
|
+
- ".dockerignore"
|
120
|
+
- ".envrc"
|
121
|
+
- ".github/workflows/main.yaml"
|
122
|
+
- ".gitignore"
|
123
|
+
- ".rspec"
|
124
|
+
- ".rubocop.yml"
|
125
|
+
- ".ruby-gemset"
|
126
|
+
- ".ruby-version"
|
127
|
+
- ".travis.yml"
|
127
128
|
- CODE_OF_CONDUCT.md
|
128
129
|
- Dockerfile
|
129
130
|
- Gemfile
|
131
|
+
- Gemfile.lock
|
130
132
|
- Guardfile
|
131
133
|
- LICENSE.txt
|
132
134
|
- README.md
|
@@ -135,6 +137,7 @@ files:
|
|
135
137
|
- bin/setup
|
136
138
|
- docker-compose.yml
|
137
139
|
- lib/rspec/apib.rb
|
140
|
+
- lib/rspec/apib/comments_parser.rb
|
138
141
|
- lib/rspec/apib/configuration.rb
|
139
142
|
- lib/rspec/apib/recorder.rb
|
140
143
|
- lib/rspec/apib/version.rb
|
@@ -150,17 +153,16 @@ require_paths:
|
|
150
153
|
- lib
|
151
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
152
155
|
requirements:
|
153
|
-
- -
|
156
|
+
- - ">="
|
154
157
|
- !ruby/object:Gem::Version
|
155
158
|
version: '0'
|
156
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
160
|
requirements:
|
158
|
-
- -
|
161
|
+
- - ">="
|
159
162
|
- !ruby/object:Gem::Version
|
160
163
|
version: '0'
|
161
164
|
requirements: []
|
162
|
-
|
163
|
-
rubygems_version: 2.0.14.1
|
165
|
+
rubygems_version: 3.0.3
|
164
166
|
signing_key:
|
165
167
|
specification_version: 4
|
166
168
|
summary: Generates API Blueprint from request specs
|