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
92fb1f1d
Commit
92fb1f1d
authored
Oct 02, 2016
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow specs to pass values to request env
Fixes #23
parent
7b919204
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
helpers.rb
lib/rspec/rails/swagger/helpers.rb
+3
-2
request_builder.rb
lib/rspec/rails/swagger/request_builder.rb
+11
-1
request_builder_spec.rb
spec/rspec/rails/swagger/request_builder_spec.rb
+18
-0
No files found.
lib/rspec/rails/swagger/helpers.rb
View file @
92fb1f1d
...
...
@@ -204,13 +204,14 @@ module RSpec
method
=
builder
.
method
path
=
[
builder
.
path
,
builder
.
query
].
join
headers
=
builder
.
headers
env
=
builder
.
env
body
=
builder
.
body
# Run the request
if
::
Rails
::
VERSION
::
MAJOR
>=
5
self
.
send
(
method
,
path
,
{
params:
body
,
headers:
headers
})
self
.
send
(
method
,
path
,
{
params:
body
,
headers:
headers
,
env:
env
})
else
self
.
send
(
method
,
path
,
body
,
headers
)
self
.
send
(
method
,
path
,
body
,
headers
.
merge
(
env
)
)
end
if
example
.
metadata
[
:capture_examples
]
...
...
lib/rspec/rails/swagger/request_builder.rb
View file @
92fb1f1d
...
...
@@ -36,7 +36,8 @@ module RSpec
##
# Returns parameters defined in the operation and path item. Providing
# a +location+ will limit the parameters by their `in` value.
# a +location+ will filter the parameters to those with a matching +in+
# value.
def
parameters
location
=
nil
path_item
=
metadata
[
:swagger_path_item
]
||
{}
operation
=
metadata
[
:swagger_operation
]
||
{}
...
...
@@ -70,6 +71,15 @@ module RSpec
headers
end
##
# If +instance+ defines an +env+ method this will return those values
# for inclusion in the Rack env hash.
def
env
return
{}
unless
instance
.
respond_to?
:env
instance
.
env
end
def
path
base_path
=
document
[
:basePath
]
||
''
# Find params in the path and replace them with values defined in
...
...
spec/rspec/rails/swagger/request_builder_spec.rb
View file @
92fb1f1d
...
...
@@ -170,6 +170,24 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
end
end
describe
'#env'
do
subject
{
described_class
.
new
(
double
(
'metadata'
),
instance
)
}
let
(
:instance
)
{
double
(
'instance'
)
}
context
'with no env method on the instance'
do
it
'returns empty hash'
do
expect
(
subject
.
env
).
to
eq
({})
end
end
context
'with env method on the instance'
do
it
'returns the results'
do
allow
(
instance
).
to
receive
(
:env
)
{
{
foo: :bar
}
}
expect
(
subject
.
env
).
to
eq
({
foo: :bar
})
end
end
end
describe
'#headers'
do
subject
{
described_class
.
new
(
double
(
'metadata'
),
instance
)
}
let
(
:instance
)
{
double
(
'instance'
)
}
...
...
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