Commit 92fb1f1d by andrew morton

Allow specs to pass values to request env

Fixes #23
parent 7b919204
...@@ -204,13 +204,14 @@ module RSpec ...@@ -204,13 +204,14 @@ module RSpec
method = builder.method method = builder.method
path = [builder.path, builder.query].join path = [builder.path, builder.query].join
headers = builder.headers headers = builder.headers
env = builder.env
body = builder.body body = builder.body
# Run the request # Run the request
if ::Rails::VERSION::MAJOR >= 5 if ::Rails::VERSION::MAJOR >= 5
self.send(method, path, {params: body, headers: headers}) self.send(method, path, {params: body, headers: headers, env: env})
else else
self.send(method, path, body, headers) self.send(method, path, body, headers.merge(env))
end end
if example.metadata[:capture_examples] if example.metadata[:capture_examples]
......
...@@ -36,7 +36,8 @@ module RSpec ...@@ -36,7 +36,8 @@ module RSpec
## ##
# Returns parameters defined in the operation and path item. Providing # 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 def parameters location = nil
path_item = metadata[:swagger_path_item] || {} path_item = metadata[:swagger_path_item] || {}
operation = metadata[:swagger_operation] || {} operation = metadata[:swagger_operation] || {}
...@@ -70,6 +71,15 @@ module RSpec ...@@ -70,6 +71,15 @@ module RSpec
headers headers
end 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 def path
base_path = document[:basePath] || '' base_path = document[:basePath] || ''
# Find params in the path and replace them with values defined in # Find params in the path and replace them with values defined in
......
...@@ -170,6 +170,24 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do ...@@ -170,6 +170,24 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
end end
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 describe '#headers' do
subject { described_class.new(double('metadata'), instance) } subject { described_class.new(double('metadata'), instance) }
let(:instance) { double('instance') } let(:instance) { double('instance') }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment