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
89a8130e
Commit
89a8130e
authored
8 years ago
by
Igor Makarov
Committed by
andrew morton
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatters for response examples (#33)
* formatters for response examples * code standard fixes
parent
a3f4a1e0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
5 deletions
+88
-5
swagger.rb
lib/rspec/rails/swagger.rb
+1
-0
formatter.rb
lib/rspec/rails/swagger/formatter.rb
+3
-5
response_formatters.rb
lib/rspec/rails/swagger/response_formatters.rb
+37
-0
formatter_spec.rb
spec/rspec/rails/swagger/formatter_spec.rb
+47
-0
No files found.
lib/rspec/rails/swagger.rb
View file @
89a8130e
...
...
@@ -3,6 +3,7 @@ require 'rspec/rails/swagger/configuration'
require
'rspec/rails/swagger/document'
require
'rspec/rails/swagger/formatter'
require
'rspec/rails/swagger/helpers'
require
'rspec/rails/swagger/response_formatters'
require
'rspec/rails/swagger/request_builder'
require
'rspec/rails/swagger/route_parser'
require
'rspec/rails/swagger/version'
...
...
This diff is collapsed.
Click to expand it.
lib/rspec/rails/swagger/formatter.rb
View file @
89a8130e
...
...
@@ -130,12 +130,10 @@ module RSpec
end
def
prepare_examples
(
examples
)
if
examples
[
'application/json'
].
kind_of?
String
begin
examples
[
'application/json'
]
=
JSON
.
parse
(
examples
[
'application/json'
])
rescue
JSON
::
ParserError
end
examples
.
each_pair
do
|
format
,
resp
|
examples
[
format
]
=
ResponseFormatters
[
format
].
call
(
resp
)
end
examples
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/rspec/rails/swagger/response_formatters.rb
0 → 100644
View file @
89a8130e
module
RSpec
module
Rails
module
Swagger
class
ResponseFormatters
class
JSON
def
call
(
resp
)
if
resp
.
kind_of?
String
::
JSON
.
parse
(
resp
)
else
resp
end
rescue
::
JSON
::
ParserError
resp
end
end
@formatters
=
{
:default
=>
->
(
resp
)
{
resp
},
'application/json'
=>
JSON
.
new
}
class
<<
self
def
register
(
format
,
callable
)
@formatters
[
format
]
=
callable
end
def
[]
(
key
)
@formatters
[
key
]
||
@formatters
[
:default
]
end
end
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/rspec/rails/swagger/formatter_spec.rb
View file @
89a8130e
...
...
@@ -65,6 +65,53 @@ RSpec.describe RSpec::Rails::Swagger::Formatter do
expect
(
formatter
.
documents
[
'doc2.json'
][
:paths
].
length
).
to
eq
(
1
)
end
end
context
"with a response examples"
do
let
(
:metadata_examples
)
{
{
'application/json'
=>
JSON
.
dump
({
foo: :bar
})}
}
let
(
:metadata
)
do
{
swagger_object: :response
,
swagger_path_item:
{
path:
"/ping"
},
swagger_operation:
{
method: :put
},
swagger_response:
{
status_code:
200
,
description:
"OK"
,
examples:
metadata_examples
},
}
end
shared_examples
'response example formatter'
do
it
"copies the requests into the document"
do
formatter
.
example_finished
(
example_notification
)
expected_paths
=
{
'/ping'
=>
{
put:
{
responses:
{
200
=>
{
examples:
output_examples
,
description:
'OK'
}}
}
}
}
expect
(
formatter
.
documents
.
values
.
first
[
:paths
]).
to
eq
(
expected_paths
)
end
end
context
"with a default formatter"
do
before
(
:example
)
do
RSpec
::
Rails
::
Swagger
::
ResponseFormatters
.
register
(
'application/json'
,
RSpec
::
Rails
::
Swagger
::
ResponseFormatters
::
JSON
.
new
)
end
let
(
:output_examples
)
{
{
'application/json'
=>
{
"foo"
=>
"bar"
}}
}
include_examples
'response example formatter'
end
context
"custom application/json formatter"
do
before
(
:example
)
do
RSpec
::
Rails
::
Swagger
::
ResponseFormatters
.
register
(
'application/json'
,
->
(
resp
)
{
resp
})
end
let
(
:output_examples
)
{
{
'application/json'
=>
JSON
.
dump
({
foo: :bar
})}
}
include_examples
'response example formatter'
end
end
end
describe
"#close"
do
...
...
This diff is collapsed.
Click to expand it.
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