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
7e77096a
Commit
7e77096a
authored
Sep 20, 2016
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaning up stuff around the params
parent
db6e3635
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
19 deletions
+30
-19
formatter.rb
lib/rspec/swagger/formatter.rb
+6
-4
helpers.rb
lib/rspec/swagger/helpers.rb
+14
-13
request_spec.rb
spec/requests/request_spec.rb
+9
-1
helpers_spec.rb
spec/rspec/swagger/helpers_spec.rb
+1
-1
No files found.
lib/rspec/swagger/formatter.rb
View file @
7e77096a
...
@@ -21,8 +21,10 @@ module RSpec
...
@@ -21,8 +21,10 @@ module RSpec
data
=
notification
.
example
.
metadata
[
:swagger_data
]
data
=
notification
.
example
.
metadata
[
:swagger_data
]
document
=
document_for
(
nil
)
document
=
document_for
(
nil
)
path
=
path_for
(
document
,
data
[
:path
])
path_item
=
path_item_for
(
document
,
data
[
:path
])
operation
=
operation_for
(
path
,
data
[
:operation
])
# TODO output path_item's parameters
operation
=
operation_for
(
path_item
,
data
[
:operation
])
# TODO output operation's parameters
response
=
response_for
(
operation
,
data
[
:status_code
])
response
=
response_for
(
operation
,
data
[
:status_code
])
response
[
:description
]
=
data
[
:response_description
]
if
data
[
:response_description
]
response
[
:description
]
=
data
[
:response_description
]
if
data
[
:response_description
]
response
[
:examples
]
=
prepare_example
(
data
[
:example
])
if
data
[
:example
]
response
[
:examples
]
=
prepare_example
(
data
[
:example
])
if
data
[
:example
]
...
@@ -37,7 +39,7 @@ module RSpec
...
@@ -37,7 +39,7 @@ module RSpec
end
end
def
write_json
(
name
,
document
)
def
write_json
(
name
,
document
)
p
p
document
p
uts
JSON
.
pretty_generate
(
document
)
end
end
def
document_for
doc_name
=
nil
def
document_for
doc_name
=
nil
...
@@ -48,7 +50,7 @@ module RSpec
...
@@ -48,7 +50,7 @@ module RSpec
end
end
end
end
def
path_for
document
,
path_name
def
path_
item_
for
document
,
path_name
document
[
:paths
]
||=
{}
document
[
:paths
]
||=
{}
document
[
:paths
][
path_name
]
||=
{}
document
[
:paths
][
path_name
]
||=
{}
end
end
...
...
lib/rspec/swagger/helpers.rb
View file @
7e77096a
...
@@ -11,7 +11,7 @@ module RSpec
...
@@ -11,7 +11,7 @@ module RSpec
config
.
extend
Operation
,
swagger_object: :operation
config
.
extend
Operation
,
swagger_object: :operation
config
.
extend
Parameters
,
swagger_object: :operation
config
.
extend
Parameters
,
swagger_object: :operation
config
.
extend
Response
,
swagger_object: :status_code
config
.
extend
Response
,
swagger_object: :status_code
config
.
include
Common
,
:swagger_object
config
.
include
Resolver
,
:swagger_object
end
end
...
@@ -105,11 +105,6 @@ paths: (Paths)
...
@@ -105,11 +105,6 @@ paths: (Paths)
describe
(
"
#{
status_code
}
"
,
meta
)
do
describe
(
"
#{
status_code
}
"
,
meta
)
do
self
.
module_exec
(
&
block
)
if
block_given?
self
.
module_exec
(
&
block
)
if
block_given?
# TODO: this needs a better mechanism
if
metadata
[
:capture_example
]
example
=
metadata
[
:swagger_data
][
:example
]
=
{}
end
before
do
|
example
|
before
do
|
example
|
method
=
example
.
metadata
[
:swagger_data
][
:operation
]
method
=
example
.
metadata
[
:swagger_data
][
:operation
]
path
=
resolve_path
(
example
.
metadata
[
:swagger_data
][
:path
],
self
)
path
=
resolve_path
(
example
.
metadata
[
:swagger_data
][
:path
],
self
)
...
@@ -119,15 +114,18 @@ paths: (Paths)
...
@@ -119,15 +114,18 @@ paths: (Paths)
[
path
,
params
,
headers
]
[
path
,
params
,
headers
]
end
end
# Run the request
self
.
send
(
method
,
*
args
)
self
.
send
(
method
,
*
args
)
# TODO fix the naming collision
if
example
.
metadata
[
:capture_example
]
# if example
example
.
metadata
[
:swagger_data
][
:example
]
=
{
# example.merge!(body: response.body, content_type: response.content_type.to_s)
body:
response
.
body
,
# end
content_type:
response
.
content_type
.
to_s
}
end
end
end
it
(
"
matches
"
,
{
swagger_object: :response
})
do
it
(
"
returns the correct status code
"
,
{
swagger_object: :response
})
do
expect
(
response
).
to
have_http_status
(
status_code
)
expect
(
response
).
to
have_http_status
(
status_code
)
end
end
end
end
...
@@ -140,17 +138,20 @@ paths: (Paths)
...
@@ -140,17 +138,20 @@ paths: (Paths)
end
end
end
end
module
Common
module
Resolver
def
resolve_params
swagger_data
,
group_instance
def
resolve_params
swagger_data
,
group_instance
params
=
swagger_data
[
:params
].
values
# TODO resolve $refs
# TODO resolve $refs
# TODO there should only be one body param
# TODO there should only be one body param
# TODO there should not be both body and formData params
# TODO there should not be both body and formData params
swagger_data
[
:params
].
value
s
.
map
do
|
p
|
param
s
.
map
do
|
p
|
p
.
slice
(
:name
,
:in
).
merge
(
value:
group_instance
.
send
(
p
[
:name
]))
p
.
slice
(
:name
,
:in
).
merge
(
value:
group_instance
.
send
(
p
[
:name
]))
end
end
end
end
def
resolve_path
template
,
group_instance
def
resolve_path
template
,
group_instance
# Should check that the parameter is actually defined before trying
# fetch a value?
template
.
gsub
(
/(\{.*?\})/
){
|
match
|
group_instance
.
send
(
match
[
1
...-
1
])
}
template
.
gsub
(
/(\{.*?\})/
){
|
match
|
group_instance
.
send
(
match
[
1
...-
1
])
}
end
end
end
end
...
...
spec/requests/request_spec.rb
View file @
7e77096a
...
@@ -8,8 +8,16 @@ RSpec.describe "Requestsing", type: :request do
...
@@ -8,8 +8,16 @@ RSpec.describe "Requestsing", type: :request do
end
end
operation
"POST"
,
"create"
do
operation
"POST"
,
"create"
do
# params
parameter
"body"
,
in: :body
let
(
:body
)
{
{
post:
{
title:
'asdf'
,
body:
"blah"
}
}
}
# TODO: it should pull the body from the params
response
(
201
,
"successfully created"
,
{
post:
{
title:
'asdf'
,
body:
"blah"
}
}.
to_json
,
{
'CONTENT_TYPE'
=>
'application/json'
,
'HTTP_ACCEPT'
=>
'application/json'
})
do
response
(
201
,
"successfully created"
,
{
post:
{
title:
'asdf'
,
body:
"blah"
}
}.
to_json
,
{
'CONTENT_TYPE'
=>
'application/json'
,
'HTTP_ACCEPT'
=>
'application/json'
})
do
it
"uses the body we passed in"
do
post
=
JSON
.
parse
(
response
.
body
)
expect
(
post
[
"title"
]).
to
eq
(
'asdf'
)
expect
(
post
[
"body"
]).
to
eq
(
'blah'
)
end
capture_example
capture_example
end
end
end
end
...
...
spec/rspec/swagger/helpers_spec.rb
View file @
7e77096a
...
@@ -83,7 +83,7 @@ RSpec.describe RSpec::Swagger::Helpers::Operation do
...
@@ -83,7 +83,7 @@ RSpec.describe RSpec::Swagger::Helpers::Operation do
end
end
RSpec
.
describe
RSpec
::
Swagger
::
Helpers
::
Common
do
RSpec
.
describe
RSpec
::
Swagger
::
Helpers
::
Resolver
do
# Tthis helper is an include rather than an extend we can get it pulled into
# Tthis helper is an include rather than an extend we can get it pulled into
# the test just by matching the filter metadata.
# the test just by matching the filter metadata.
describe
(
"#resolve_params"
,
swagger_object: :something
)
do
describe
(
"#resolve_params"
,
swagger_object: :something
)
do
...
...
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