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
8 years ago
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Few cleanups
parent
22adfbaa
Hide 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://
-
install gem
-
`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
...
...
This diff is collapsed.
Click to expand it.
lib/rspec/swagger/helpers.rb
View file @
c235162b
...
...
@@ -174,15 +174,15 @@ module RSpec
before
do
|
example
|
builder
=
RequestBuilder
.
new
(
example
.
metadata
,
self
)
method
=
builder
.
method
path
=
builder
.
path
+
builder
.
query
path
=
[
builder
.
path
,
builder
.
query
].
join
headers
=
builder
.
headers
params
=
resolve_params
(
example
.
metadata
,
self
)
body
=
builder
.
body
# Run the request
if
::
Rails
::
VERSION
::
MAJOR
>=
5
self
.
send
(
method
,
path
,
{
params:
params
,
headers:
headers
})
self
.
send
(
method
,
path
,
{
params:
body
,
headers:
headers
})
else
self
.
send
(
method
,
path
,
params
,
headers
)
self
.
send
(
method
,
path
,
body
,
headers
)
end
if
example
.
metadata
[
:capture_example
]
...
...
This diff is collapsed.
Click to expand it.
lib/rspec/swagger/request_builder.rb
View file @
c235162b
...
...
@@ -49,22 +49,24 @@ module RSpec
# in the example group.
path
=
base_path
+
metadata
[
:swagger_path_item
][
:path
].
gsub
(
/(\{.*?\})/
)
do
|
match
|
# 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
])
end
end
def
query
# Don't bother with the parameter bodies since all we need is location
# and name which make up the key.
query_params
=
parameters
.
keys
.
map
{
|
k
|
k
.
split
(
'&'
)}
# Don't bother looking at the full parameter bodies since all we need
# are location and name which are the key.
query_params
=
parameters
.
keys
.
map
{
|
k
|
k
.
split
(
'&'
)}
.
select
{
|
location
,
name
|
location
==
'query'
}
.
map
{
|
location
,
name
|
[
name
,
instance
.
send
(
name
)]
}
'?'
+
Hash
[
query_params
].
to_query
unless
query_params
.
empty?
end
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&'
}
instance
.
send
(
key
.
split
(
'&'
).
last
).
to_json
end
...
...
This diff is collapsed.
Click to expand it.
spec/requests/request_spec.rb
View file @
c235162b
...
...
@@ -42,7 +42,6 @@ RSpec.describe "Requestsing", type: :request do
produces
'application/json'
before
{
Post
.
new
.
save
}
parameter
"op-param"
,
{
in: :query
,
type: :string
}
response
(
200
,
{
description:
"success"
},
{})
do
capture_example
end
...
...
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