Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rspec-rails-swagger
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rspec-rails-swagger
Commits
9bff4422
Commit
9bff4422
authored
Sep 27, 2016
by
andrew morton
Committed by
GitHub
Sep 27, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11 from drewish/formatter-output
Show path, method and status code while generating docs
parents
b8d7d6a0
d6556e33
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
9 deletions
+48
-9
formatter.rb
lib/rspec/rails/swagger/formatter.rb
+48
-9
No files found.
lib/rspec/rails/swagger/formatter.rb
View file @
9bff4422
require
'rspec/core/formatters/base_text_formatter'
RSpec
::
Support
.
require_rspec_core
"formatters/base_text_formatter"
RSpec
::
Support
.
require_rspec_core
"formatters/console_codes"
module
RSpec
module
Rails
module
Swagger
class
Formatter
<
RSpec
::
Core
::
Formatters
::
BaseTextFormatter
RSpec
::
Core
::
Formatters
.
register
self
,
:example_finished
,
:close
RSpec
::
Core
::
Formatters
.
register
self
,
:example_group_started
,
:example_passed
,
:example_pending
,
:example_failed
,
:example_finished
,
:close
def
documents
# We don't try to load the docs in `initalize` because when running
...
...
@@ -13,22 +16,58 @@ module RSpec
@documents
||=
::
RSpec
.
configuration
.
swagger_docs
end
def
example_group_started
(
notification
)
output
.
print
*
group_output
(
notification
)
end
def
example_passed
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:success
)
end
def
example_pending
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:pending
)
end
def
example_failed
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:failure
)
end
def
example_finished
(
notification
)
metadata
=
notification
.
example
.
metadata
return
unless
metadata
[
:swagger_object
]
==
:response
# metadata.each do |k, v|
# puts "#{k}\t#{v}" if k.to_s.starts_with?("swagger")
# end
# Then add everything to the document
document
=
document_for
(
metadata
[
:swagger_document
])
path_item
=
path_item_for
(
document
,
metadata
[
:swagger_path_item
])
operation
=
operation_for
(
path_item
,
metadata
[
:swagger_operation
])
response_for
(
operation
,
metadata
[
:swagger_response
])
response
=
response_for
(
operation
,
metadata
[
:swagger_response
])
end
def
close
(
_notification
)
documents
.
each
{
|
k
,
v
|
write_json
(
k
,
v
)}
self
end
private
def
group_output
(
notification
)
metadata
=
notification
.
group
.
metadata
# This is a little odd because I didn't want to split the logic across
# a start and end method. Instead we just start a new line for each
# path and operation and just let the status codes pile up on the end.
# There's probably a better way that doesn't have the initial newline.
case
metadata
[
:swagger_object
]
when
:path_item
[
"
\n
"
,
metadata
[
:swagger_path_item
][
:path
]]
when
:operation
[
"
\n
"
,
metadata
[
:swagger_operation
][
:method
].
to_s
,
"
\t
"
]
end
end
def
example_output
(
notification
)
"
#{
notification
.
example
.
metadata
[
:swagger_response
][
:status_code
]
}
"
end
def
write_json
(
name
,
document
)
...
...
@@ -91,9 +130,9 @@ module RSpec
end
def
prepare_examples
(
examples
)
if
examples
[
"application/json"
].
present?
if
examples
[
'application/json'
].
kind_of?
String
begin
examples
[
"application/json"
]
=
JSON
.
parse
(
examples
[
"application/json"
])
examples
[
'application/json'
]
=
JSON
.
parse
(
examples
[
'application/json'
])
rescue
JSON
::
ParserError
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment