Commit 92fb1f1d by andrew morton

Allow specs to pass values to request env

Fixes #23
parent 7b919204
......@@ -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]
......
......@@ -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
......
......@@ -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') }
......
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