rspec_api_documentation 3.1.0 → 4.0.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: b7e6c19ee26d9e8b093eda724140422fd0752308
4
- data.tar.gz: 852e00b740d884e07466feebfbfbf34dd98b18f4
3
+ metadata.gz: 9cff1f54aa57141a0f21909348c9cf326a75ea93
4
+ data.tar.gz: 356b837bc052ff05738e2d95cbfec04e1c3a6cf5
5
5
  SHA512:
6
- metadata.gz: b84b411b63bae9373d07dd30040a9c2dc64d789b6718d84da867f3774bb2a54731aa67fb2d5a530a1332d4562f3055e021e27c9087434de5b1c6be820fc02675
7
- data.tar.gz: 6e994149dcb0875ca38ec9d6ad9a26d6f86e879294ffba13b5c1b4da4dc3f08b3ad37aec69cdc10c3e8baf44369b6284a5024cbaf5589e99c19893fb35c75c7b
6
+ metadata.gz: 80c655256dc7447ef2af3ee6abf54569ea05730216cae2ae1408ddaf1de4028b75979a759247c4a5615a86a9a9d47a723dc129af1b32832db68b5926d0597ee9
7
+ data.tar.gz: 3feddb137db8775facd2c454304fe8e4793fc61add4c050ea27235bf62c2d6ee75f3359b4982186aa66773a84d0bdba6cb135b1c13fbac8148b015a6e3bb6bdf
@@ -2,43 +2,39 @@ require 'rspec/core/formatters/base_text_formatter'
2
2
 
3
3
  module RspecApiDocumentation
4
4
  class ApiFormatter < RSpec::Core::Formatters::BaseTextFormatter
5
+ RSpec::Core::Formatters.register self, :example_passed, :example_failed, :stop
6
+
5
7
  def initialize(output)
6
8
  super
7
9
 
8
10
  output.puts "Generating API Docs"
9
11
  end
10
12
 
11
- def start(example_count)
13
+ def start(notification)
12
14
  super
13
15
 
14
16
  RspecApiDocumentation.documentations.each(&:clear_docs)
15
17
  end
16
18
 
17
- def example_group_started(example_group)
19
+ def example_group_started(notification)
18
20
  super
19
21
 
20
- output.puts " #{example_group.description}"
22
+ output.puts " #{@example_group.description}"
21
23
  end
22
24
 
23
- def example_passed(example)
24
- super
25
-
26
- output.puts " * #{example.description}"
25
+ def example_passed(example_notification)
26
+ output.puts " * #{example_notification.example.description}"
27
27
 
28
28
  RspecApiDocumentation.documentations.each do |documentation|
29
- documentation.document_example(example)
29
+ documentation.document_example(example_notification.example)
30
30
  end
31
31
  end
32
32
 
33
- def example_failed(example)
34
- super
35
-
36
- output.puts " ! #{example.description} (FAILED)"
33
+ def example_failed(example_notification)
34
+ output.puts " ! #{example_notification.example.description} (FAILED)"
37
35
  end
38
36
 
39
- def stop
40
- super
41
-
37
+ def stop(notification)
42
38
  RspecApiDocumentation.documentations.each(&:write)
43
39
  end
44
40
  end
@@ -24,4 +24,4 @@ end
24
24
  RSpec.configuration.include RspecApiDocumentation::DSL::Resource, :api_doc_dsl => :resource
25
25
  RSpec.configuration.include RspecApiDocumentation::DSL::Endpoint, :api_doc_dsl => :endpoint
26
26
  RSpec.configuration.include RspecApiDocumentation::DSL::Callback, :api_doc_dsl => :callback
27
- RSpec.configuration.backtrace_exclusion_patterns << %r{lib/rspec_api_documentation/dsl\.rb}
27
+ RSpec.configuration.backtrace_exclusion_patterns << %r{lib/rspec_api_documentation/dsl/}
@@ -16,7 +16,7 @@ module RspecApiDocumentation::DSL
16
16
  end
17
17
 
18
18
  def destination
19
- @destination ||= RspecApiDocumentation::TestServer.new(self)
19
+ @destination ||= RspecApiDocumentation::TestServer.new(RSpec.current_example)
20
20
  end
21
21
 
22
22
  def callback_url
@@ -12,12 +12,7 @@ module RspecApiDocumentation::DSL
12
12
 
13
13
  module ClassMethods
14
14
  def example_request(description, params = {}, &block)
15
- file_path = caller.first[0, caller.first =~ /:/]
16
-
17
- location = caller.first[0, caller.first =~ /(:in|$)/]
18
- location = relative_path(location)
19
-
20
- example description, :location => location, :file_path => file_path do
15
+ example description, :caller => block.send(:caller) do
21
16
  do_request(params)
22
17
  instance_eval &block if block_given?
23
18
  end
@@ -106,6 +101,10 @@ module RspecApiDocumentation::DSL
106
101
  example.metadata[:explanation] = text
107
102
  end
108
103
 
104
+ def example
105
+ RSpec.current_example
106
+ end
107
+
109
108
  private
110
109
 
111
110
  def rspec_api_documentation_client
@@ -42,6 +42,10 @@ module RspecApiDocumentation::DSL
42
42
  parameters.push(options.merge(:name => name.to_s, :description => description))
43
43
  end
44
44
 
45
+ def response_field(name, description, options = {})
46
+ response_fields.push(options.merge(:name => name.to_s, :description => description))
47
+ end
48
+
45
49
  def header(name, value)
46
50
  headers[name] = value
47
51
  end
@@ -55,6 +59,14 @@ module RspecApiDocumentation::DSL
55
59
  metadata[:parameters]
56
60
  end
57
61
 
62
+ def response_fields
63
+ metadata[:response_fields] ||= []
64
+ if superclass_metadata && metadata[:response_fields].equal?(superclass_metadata[:response_fields])
65
+ metadata[:response_fields] = Marshal.load(Marshal.dump(superclass_metadata[:response_fields]))
66
+ end
67
+ metadata[:response_fields]
68
+ end
69
+
58
70
  def headers
59
71
  metadata[:headers] ||= {}
60
72
  if superclass_metadata && metadata[:headers].equal?(superclass_metadata[:headers])
@@ -38,6 +38,10 @@ module RspecApiDocumentation
38
38
  respond_to?(:parameters) && parameters.present?
39
39
  end
40
40
 
41
+ def has_response_fields?
42
+ respond_to?(:response_fields) && response_fields.present?
43
+ end
44
+
41
45
  def explanation
42
46
  metadata[:explanation] || nil
43
47
  end
@@ -1,8 +1,7 @@
1
1
  module RspecApiDocumentation
2
- class TestServer < Struct.new(:context)
2
+ class TestServer < Struct.new(:example)
3
3
  include Headers
4
4
 
5
- delegate :example, :to => :context
6
5
  delegate :metadata, :to => :example
7
6
 
8
7
  attr_reader :request_method, :request_headers, :request_body
@@ -19,11 +19,11 @@ module RspecApiDocumentation
19
19
  end
20
20
 
21
21
  def dirname
22
- resource_name.downcase.gsub(/[^0-9a-z.\-]+/, '_')
22
+ resource_name.downcase.gsub(/\s+/, '_').gsub(":", "_")
23
23
  end
24
24
 
25
25
  def filename
26
- basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
26
+ basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
27
27
  basename = Digest::MD5.new.update(description).to_s if basename.blank?
28
28
  "#{basename}.#{extension}"
29
29
  end
@@ -78,7 +78,7 @@ module RspecApiDocumentation
78
78
  end
79
79
 
80
80
  def filename
81
- basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
81
+ basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
82
82
  "#{basename}.json"
83
83
  end
84
84
 
@@ -90,6 +90,7 @@ module RspecApiDocumentation
90
90
  :description => description,
91
91
  :explanation => explanation,
92
92
  :parameters => respond_to?(:parameters) ? parameters : [],
93
+ :response_fields => respond_to?(:response_fields) ? response_fields : [],
93
94
  :requests => requests
94
95
  }
95
96
  end
@@ -69,6 +69,35 @@
69
69
  </table>
70
70
  {{/ has_parameters? }}
71
71
 
72
+ {{# has_response_fields? }}
73
+ <h3>Response Fields</h3>
74
+ <table class="response-fields table table-striped table-bordered table-condensed">
75
+ <thead>
76
+ <tr>
77
+ <th>Name</th>
78
+ <th>Description</th>
79
+ </tr>
80
+ </thead>
81
+ <tbody>
82
+ {{# response_fields }}
83
+ <tr>
84
+ <td>
85
+ {{# scope }}
86
+ <span class="name">{{ scope }}[{{ name }}]</span>
87
+ {{/ scope }}
88
+ {{^ scope }}
89
+ <span class="name">{{ name }}</span>
90
+ {{/ scope }}
91
+ </td>
92
+ <td>
93
+ <span class="description">{{ description }}</span>
94
+ </td>
95
+ </tr>
96
+ {{/ response_fields }}
97
+ </tbody>
98
+ </table>
99
+ {{/ has_response_fields? }}
100
+
72
101
  {{# requests }}
73
102
  <h3>Request</h3>
74
103
 
@@ -3,20 +3,30 @@
3
3
  ## {{ description }}
4
4
 
5
5
  ### {{ http_method }} {{ route }}
6
-
7
6
  {{# explanation }}
7
+
8
8
  {{ explanation }}
9
9
  {{/ explanation }}
10
-
11
10
  {{# has_parameters? }}
11
+
12
12
  ### Parameters
13
13
  {{# parameters }}
14
14
 
15
- Name : {{ name }} {{# required }} *- required -*{{/ required }}
15
+ Name : {{ name }}{{# required }} *- required -*{{/ required }}
16
16
  Description : {{ description }}
17
17
  {{/ parameters }}
18
+
18
19
  {{/ has_parameters? }}
20
+ {{# has_response_fields? }}
21
+
22
+ ### Response Fields
23
+ {{# response_fields }}
24
+
25
+ Name : {{ name }}
26
+ Description : {{ description }}
27
+ {{/ response_fields }}
19
28
 
29
+ {{/ has_response_fields? }}
20
30
  {{# requests }}
21
31
  ### Request
22
32
 
@@ -27,20 +37,20 @@ Description : {{ description }}
27
37
  #### Route
28
38
 
29
39
  <pre>{{ request_method }} {{ request_path }}</pre>
30
-
31
40
  {{# request_query_parameters_text }}
41
+
32
42
  #### Query Parameters
33
43
 
34
44
  <pre>{{ request_query_parameters_text }}</pre>
35
45
  {{/ request_query_parameters_text }}
36
-
37
46
  {{# request_body }}
47
+
38
48
  #### Body
39
49
 
40
50
  <pre>{{{ request_body }}}</pre>
41
51
  {{/ request_body }}
42
-
43
52
  {{# curl }}
53
+
44
54
  #### cURL
45
55
 
46
56
  <pre class="request">{{ curl }}</pre>
@@ -63,6 +73,4 @@ Description : {{ description }}
63
73
  <pre>{{{ response_body }}}</pre>
64
74
  {{/ response_body }}
65
75
  {{/ response_status }}
66
-
67
76
  {{/ requests }}
68
-
@@ -6,8 +6,8 @@ h3. {{ http_method }} {{ route }}
6
6
 
7
7
  {{# explanation }}
8
8
  {{ explanation }}
9
- {{/ explanation }}
10
9
 
10
+ {{/ explanation }}
11
11
  {{# has_parameters? }}
12
12
  h3. Parameters
13
13
  {{# parameters }}
@@ -15,8 +15,17 @@ h3. Parameters
15
15
  Name : {{ name }} {{# required }} *- required -*{{/ required }}
16
16
  Description : {{ description }}
17
17
  {{/ parameters }}
18
+
18
19
  {{/ has_parameters? }}
20
+ {{# has_response_fields? }}
21
+ h3. Response Fields
22
+ {{# response_fields }}
19
23
 
24
+ Name : {{ name }}
25
+ Description : {{ description }}
26
+ {{/ response_fields }}
27
+
28
+ {{/ has_response_fields? }}
20
29
  {{# requests }}
21
30
  h3. Request
22
31
 
@@ -32,20 +41,20 @@ h4. Route
32
41
  h4. Query Parameters
33
42
 
34
43
  <pre>{{ request_query_parameters_text }}</pre>
35
- {{/ request_query_parameters_text }}
36
44
 
45
+ {{/ request_query_parameters_text }}
37
46
  {{# request_body }}
38
47
  h4. Body
39
48
 
40
49
  <pre>{{{ request_body }}}</pre>
41
- {{/ request_body }}
42
50
 
51
+ {{/ request_body }}
43
52
  {{# curl }}
44
53
  h4. cURL
45
54
 
46
55
  <pre class="request">{{ curl }}</pre>
47
- {{/ curl }}
48
56
 
57
+ {{/ curl }}
49
58
  {{# response_status }}
50
59
  h3. Response
51
60
 
@@ -61,8 +70,7 @@ h4. Status
61
70
  h4. Body
62
71
 
63
72
  <pre>{{{ response_body }}}</pre>
73
+
64
74
  {{/ response_body }}
65
75
  {{/ response_status }}
66
-
67
76
  {{/ requests }}
68
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Cahoon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-27 00:00:00.000000000 Z
13
+ date: 2014-06-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -18,20 +18,20 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 2.14.0
21
+ version: 3.0.0
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.14.0
24
+ version: 3.0.0
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - "~>"
30
30
  - !ruby/object:Gem::Version
31
- version: 2.14.0
31
+ version: 3.0.0
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.14.0
34
+ version: 3.0.0
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activesupport
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -46,24 +46,13 @@ dependencies:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 3.0.0
49
- - !ruby/object:Gem::Dependency
50
- name: i18n
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 0.1.0
56
- type: :runtime
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.1.0
63
49
  - !ruby/object:Gem::Dependency
64
50
  name: mustache
65
51
  requirement: !ruby/object:Gem::Requirement
66
52
  requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.99'
67
56
  - - ">="
68
57
  - !ruby/object:Gem::Version
69
58
  version: 0.99.4
@@ -71,6 +60,9 @@ dependencies:
71
60
  prerelease: false
72
61
  version_requirements: !ruby/object:Gem::Requirement
73
62
  requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '0.99'
74
66
  - - ">="
75
67
  - !ruby/object:Gem::Version
76
68
  version: 0.99.4
@@ -78,6 +70,9 @@ dependencies:
78
70
  name: json
79
71
  requirement: !ruby/object:Gem::Requirement
80
72
  requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
81
76
  - - ">="
82
77
  - !ruby/object:Gem::Version
83
78
  version: 1.4.6
@@ -85,6 +80,9 @@ dependencies:
85
80
  prerelease: false
86
81
  version_requirements: !ruby/object:Gem::Requirement
87
82
  requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.4'
88
86
  - - ">="
89
87
  - !ruby/object:Gem::Version
90
88
  version: 1.4.6
@@ -92,114 +90,128 @@ dependencies:
92
90
  name: fakefs
93
91
  requirement: !ruby/object:Gem::Requirement
94
92
  requirements:
95
- - - ">="
93
+ - - "~>"
96
94
  - !ruby/object:Gem::Version
97
- version: '0'
95
+ version: '0.4'
98
96
  type: :development
99
97
  prerelease: false
100
98
  version_requirements: !ruby/object:Gem::Requirement
101
99
  requirements:
102
- - - ">="
100
+ - - "~>"
103
101
  - !ruby/object:Gem::Version
104
- version: '0'
102
+ version: '0.4'
105
103
  - !ruby/object:Gem::Dependency
106
104
  name: sinatra
107
105
  requirement: !ruby/object:Gem::Requirement
108
106
  requirements:
109
- - - ">="
107
+ - - "~>"
110
108
  - !ruby/object:Gem::Version
111
- version: '0'
109
+ version: 1.4.4
112
110
  type: :development
113
111
  prerelease: false
114
112
  version_requirements: !ruby/object:Gem::Requirement
115
113
  requirements:
116
- - - ">="
114
+ - - "~>"
117
115
  - !ruby/object:Gem::Version
118
- version: '0'
116
+ version: 1.4.4
119
117
  - !ruby/object:Gem::Dependency
120
118
  name: aruba
121
119
  requirement: !ruby/object:Gem::Requirement
122
120
  requirements:
123
- - - ">="
121
+ - - "~>"
124
122
  - !ruby/object:Gem::Version
125
- version: '0'
123
+ version: '0.5'
126
124
  type: :development
127
125
  prerelease: false
128
126
  version_requirements: !ruby/object:Gem::Requirement
129
127
  requirements:
130
- - - ">="
128
+ - - "~>"
131
129
  - !ruby/object:Gem::Version
132
- version: '0'
130
+ version: '0.5'
133
131
  - !ruby/object:Gem::Dependency
134
132
  name: capybara
135
133
  requirement: !ruby/object:Gem::Requirement
136
134
  requirements:
137
- - - ">="
135
+ - - "~>"
138
136
  - !ruby/object:Gem::Version
139
- version: '0'
137
+ version: '2.2'
140
138
  type: :development
141
139
  prerelease: false
142
140
  version_requirements: !ruby/object:Gem::Requirement
143
141
  requirements:
144
- - - ">="
142
+ - - "~>"
145
143
  - !ruby/object:Gem::Version
146
- version: '0'
144
+ version: '2.2'
147
145
  - !ruby/object:Gem::Dependency
148
146
  name: rake
149
147
  requirement: !ruby/object:Gem::Requirement
150
148
  requirements:
151
- - - ">="
149
+ - - "~>"
152
150
  - !ruby/object:Gem::Version
153
- version: '0'
151
+ version: '10.1'
154
152
  type: :development
155
153
  prerelease: false
156
154
  version_requirements: !ruby/object:Gem::Requirement
157
155
  requirements:
158
- - - ">="
156
+ - - "~>"
159
157
  - !ruby/object:Gem::Version
160
- version: '0'
158
+ version: '10.1'
161
159
  - !ruby/object:Gem::Dependency
162
160
  name: rack-test
163
161
  requirement: !ruby/object:Gem::Requirement
164
162
  requirements:
165
- - - ">="
163
+ - - "~>"
166
164
  - !ruby/object:Gem::Version
167
165
  version: 0.6.2
168
166
  type: :development
169
167
  prerelease: false
170
168
  version_requirements: !ruby/object:Gem::Requirement
171
169
  requirements:
172
- - - ">="
170
+ - - "~>"
173
171
  - !ruby/object:Gem::Version
174
172
  version: 0.6.2
175
173
  - !ruby/object:Gem::Dependency
176
174
  name: rack-oauth2
177
175
  requirement: !ruby/object:Gem::Requirement
178
176
  requirements:
179
- - - ">="
177
+ - - "~>"
180
178
  - !ruby/object:Gem::Version
181
- version: 0.14.4
179
+ version: 1.0.7
182
180
  type: :development
183
181
  prerelease: false
184
182
  version_requirements: !ruby/object:Gem::Requirement
185
183
  requirements:
186
- - - ">="
184
+ - - "~>"
187
185
  - !ruby/object:Gem::Version
188
- version: 0.14.4
186
+ version: 1.0.7
189
187
  - !ruby/object:Gem::Dependency
190
188
  name: webmock
191
189
  requirement: !ruby/object:Gem::Requirement
192
190
  requirements:
193
- - - ">="
191
+ - - "~>"
194
192
  - !ruby/object:Gem::Version
195
- version: 1.7.0
193
+ version: '1.7'
196
194
  type: :development
197
195
  prerelease: false
198
196
  version_requirements: !ruby/object:Gem::Requirement
199
197
  requirements:
200
- - - ">="
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '1.7'
201
+ - !ruby/object:Gem::Dependency
202
+ name: rspec-its
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '1.0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
201
213
  - !ruby/object:Gem::Version
202
- version: 1.7.0
214
+ version: '1.0'
203
215
  description: Generate API docs from your test suite
204
216
  email:
205
217
  - chris@smartlogicsolutions.com