rspec-apib 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 384eec940b1092adf3511086a1d277914998a2bf
4
- data.tar.gz: 3baef0e080b224033306dc0fdf31b42ebbb9796b
3
+ metadata.gz: 3a86d793744f7736b09fa16e8cb5f3eb3c092528
4
+ data.tar.gz: 1978a2e469135b871f26da73ebf3636b8d48fc74
5
5
  SHA512:
6
- metadata.gz: 9bdf908d36b862e434c22e002d0aa9e4ba57eab60f9f779e2c7cf4b8dd6ef8992a6f4a4f60bdad235bdc098b06045a118d48006e524ea042b917428c0b3a22ea
7
- data.tar.gz: 00e1d571d7fc3688e20f3c3b9cba33c0664cf54fb8c1df43962cb46b4774faf9ec3c48420fc0a4beef0ddea32fee34dd7afed8beba8f9b45e3188b744a8c7fd1
6
+ metadata.gz: 09ec789ce64972bba5d445217521d024e138caa8431e37f59778b529b9a97e3d7263a014e2c355a7838512ac88dd78c04eb95e39c409adcc1680643f4d19ffbb
7
+ data.tar.gz: 83c8da9ba36881a53826bb14dc09daf8c8cf1d32769861fc1952905e01d8c7c2328b754de52bf80d6071cf0dede0d34fafbb899d9519112c14fdffa7a29cd96c
data/README.md CHANGED
@@ -45,6 +45,38 @@ end
45
45
  RSpec::Apib.start
46
46
  ```
47
47
 
48
+ ### Writing tests
49
+
50
+ By default, request specs get recorded and written to a `.apib` file afterwards.
51
+ Rspec-apib is trying to make sense of the test run and generates a meaningful
52
+ documentation out of it.
53
+
54
+ * **Disable single examples:** Add `apib: false` to the examples meta data
55
+ ```ruby
56
+ it 'does something', apib: false do
57
+ # ...
58
+ end
59
+ ```
60
+
61
+ * **Custom example description:** Add an *apib* comment above the example
62
+ ```ruby
63
+ # Not contained in the description
64
+ #
65
+ # --- apib
66
+ # Some awesome description of the response
67
+ #
68
+ # ```json
69
+ # {}
70
+ # ```
71
+ # ---
72
+ #
73
+ # Not contained in the description
74
+ #
75
+ it 'has a custom description' do
76
+ # ...
77
+ end
78
+ ```
79
+
48
80
  ## Development
49
81
 
50
82
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -114,6 +114,7 @@ module RSpec
114
114
  next unless k.starts_with?('HTTP_')
115
115
  header = k.gsub('HTTP_', '').downcase
116
116
  next if request_header_blacklist.include? header
117
+ next if v.nil? || v.empty?
117
118
  action[:request][:headers][header] = v
118
119
  end
119
120
  end
@@ -135,7 +136,7 @@ module RSpec
135
136
  def document_response
136
137
  data = {}
137
138
  return if response_exists?
138
- data[:description] = example.description
139
+ data[:description] = document_extended_description || example.description
139
140
  data[:status] = response.status
140
141
  data[:content_type] = response.content_type.to_s
141
142
  data[:body] = response.body
@@ -143,6 +144,35 @@ module RSpec
143
144
  action[:response] << data
144
145
  end
145
146
 
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\W*#/)) do
158
+ if lines[i - 1].match(/\A\W*# --- 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\W*#/)) do
167
+ if lines[i].match(/\A\W*# ---/)
168
+ break
169
+ end
170
+ result << lines[i].sub(/^\W*#\W*/, '').strip
171
+ i += 1
172
+ end
173
+ return result.join("\n")
174
+ end
175
+
146
176
  def response_exists?
147
177
  action[:response].any? { |r| r[:status] == response.status }
148
178
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Apib
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/lib/rspec/apib.rb CHANGED
@@ -25,9 +25,9 @@ module RSpec
25
25
  types = config.record_types
26
26
  RSpec.configure do |config|
27
27
  config.after :each do |example|
28
- if types.include?(example.metadata[:type])
29
- RSpec::Apib.record(example, request, response, @routes)
30
- end
28
+ return if example.metadata[:apib] === false
29
+ return unless types.include?(example.metadata[:type])
30
+ RSpec::Apib.record(example, request, response, @routes)
31
31
  end
32
32
 
33
33
  config.after :all do |example|
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-apib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.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: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-10-18 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
19
  version: '1.10'
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
26
  version: '1.10'
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
33
  version: '10.0'
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
40
  version: '10.0'
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
47
  version: 2.13.0
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
54
  version: 2.13.0
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
61
  version: 4.6.4
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
68
  version: 4.6.4
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
89
  version: '4.2'
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
96
  version: '4.2'
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
103
  version: '3.4'
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
110
  version: '3.4'
111
111
  description:
@@ -115,15 +115,15 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".codeclimate.yml"
119
- - ".dockerignore"
120
- - ".envrc"
121
- - ".gitignore"
122
- - ".rspec"
123
- - ".rubocop.yml"
124
- - ".ruby-gemset"
125
- - ".ruby-version"
126
- - ".travis.yml"
118
+ - .codeclimate.yml
119
+ - .dockerignore
120
+ - .envrc
121
+ - .gitignore
122
+ - .rspec
123
+ - .rubocop.yml
124
+ - .ruby-gemset
125
+ - .ruby-version
126
+ - .travis.yml
127
127
  - CODE_OF_CONDUCT.md
128
128
  - Dockerfile
129
129
  - Gemfile
@@ -150,17 +150,17 @@ require_paths:
150
150
  - lib
151
151
  required_ruby_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - ">="
153
+ - - '>='
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - ">="
158
+ - - '>='
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.6.12
163
+ rubygems_version: 2.0.14.1
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Generates API Blueprint from request specs