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
c235162b
Commit
c235162b
authored
Sep 24, 2016
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Few cleanups
parent
22adfbaa
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
11 deletions
+19
-11
README.md
README.md
+8
-1
helpers.rb
lib/rspec/swagger/helpers.rb
+4
-4
request_builder.rb
lib/rspec/swagger/request_builder.rb
+7
-5
request_spec.rb
spec/requests/request_spec.rb
+0
-1
No files found.
README.md
View file @
c235162b
...
@@ -6,7 +6,14 @@ The design of this is heavily influenced by the awesome [swagger_rails](https://
...
@@ -6,7 +6,14 @@ The design of this is heavily influenced by the awesome [swagger_rails](https://
-
install gem
-
install gem
-
`rails generate rspec:install`
-
`rails generate rspec:install`
-
create
`spec/swagger_helper.rb`
... would be nice to be a generator
-
create
`spec/swagger_helper.rb`
(I'll try to get a generator to automate this)
-
define your tests (I definitely need to make this step more explicit)
## Generate the docs
```
bundle exec rspec -f RSpec::Swagger::Formatter --order defined -t swagger_object
```
## Running tests
## Running tests
...
...
lib/rspec/swagger/helpers.rb
View file @
c235162b
...
@@ -174,15 +174,15 @@ module RSpec
...
@@ -174,15 +174,15 @@ module RSpec
before
do
|
example
|
before
do
|
example
|
builder
=
RequestBuilder
.
new
(
example
.
metadata
,
self
)
builder
=
RequestBuilder
.
new
(
example
.
metadata
,
self
)
method
=
builder
.
method
method
=
builder
.
method
path
=
builder
.
path
+
builder
.
query
path
=
[
builder
.
path
,
builder
.
query
].
join
headers
=
builder
.
headers
headers
=
builder
.
headers
params
=
resolve_params
(
example
.
metadata
,
self
)
body
=
builder
.
body
# Run the request
# Run the request
if
::
Rails
::
VERSION
::
MAJOR
>=
5
if
::
Rails
::
VERSION
::
MAJOR
>=
5
self
.
send
(
method
,
path
,
{
params:
params
,
headers:
headers
})
self
.
send
(
method
,
path
,
{
params:
body
,
headers:
headers
})
else
else
self
.
send
(
method
,
path
,
params
,
headers
)
self
.
send
(
method
,
path
,
body
,
headers
)
end
end
if
example
.
metadata
[
:capture_example
]
if
example
.
metadata
[
:capture_example
]
...
...
lib/rspec/swagger/request_builder.rb
View file @
c235162b
...
@@ -49,22 +49,24 @@ module RSpec
...
@@ -49,22 +49,24 @@ module RSpec
# in the example group.
# in the example group.
path
=
base_path
+
metadata
[
:swagger_path_item
][
:path
].
gsub
(
/(\{.*?\})/
)
do
|
match
|
path
=
base_path
+
metadata
[
:swagger_path_item
][
:path
].
gsub
(
/(\{.*?\})/
)
do
|
match
|
# QUESTION: Should check that the parameter is actually defined in
# QUESTION: Should check that the parameter is actually defined in
# `
metadata[:swagger_*][:parameters]
` before fetch a value?
# `
parameters
` before fetch a value?
instance
.
send
(
match
[
1
...-
1
])
instance
.
send
(
match
[
1
...-
1
])
end
end
end
end
def
query
def
query
# Don't bother with the parameter bodies since all we need is location
# Don't bother looking at the full parameter bodies since all we need
# and name which make up the key.
# are location and name which are the key.
query_params
=
parameters
.
keys
query_params
=
parameters
.
keys
.
map
{
|
k
|
k
.
split
(
'&'
)}
.
map
{
|
k
|
k
.
split
(
'&'
)}
.
select
{
|
location
,
name
|
location
==
'query'
}
.
select
{
|
location
,
name
|
location
==
'query'
}
.
map
{
|
location
,
name
|
[
name
,
instance
.
send
(
name
)]
}
.
map
{
|
location
,
name
|
[
name
,
instance
.
send
(
name
)]
}
'?'
+
Hash
[
query_params
].
to_query
unless
query_params
.
empty?
'?'
+
Hash
[
query_params
].
to_query
unless
query_params
.
empty?
end
end
def
body
def
body
# And here all we need is the first half of the key to find the body
# parameter and its name to fetch a value.
if
key
=
parameters
.
keys
.
find
{
|
k
|
k
.
starts_with?
'body&'
}
if
key
=
parameters
.
keys
.
find
{
|
k
|
k
.
starts_with?
'body&'
}
instance
.
send
(
key
.
split
(
'&'
).
last
).
to_json
instance
.
send
(
key
.
split
(
'&'
).
last
).
to_json
end
end
...
...
spec/requests/request_spec.rb
View file @
c235162b
...
@@ -42,7 +42,6 @@ RSpec.describe "Requestsing", type: :request do
...
@@ -42,7 +42,6 @@ RSpec.describe "Requestsing", type: :request do
produces
'application/json'
produces
'application/json'
before
{
Post
.
new
.
save
}
before
{
Post
.
new
.
save
}
parameter
"op-param"
,
{
in: :query
,
type: :string
}
response
(
200
,
{
description:
"success"
},
{})
do
response
(
200
,
{
description:
"success"
},
{})
do
capture_example
capture_example
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