mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-24 23:06:41 +00:00
69 lines
2.0 KiB
Ruby
69 lines
2.0 KiB
Ruby
require 'rswag/specs/example_helpers'
|
|
|
|
module Rswag
|
|
module Specs
|
|
|
|
describe ExampleHelpers do
|
|
subject { double('example') }
|
|
|
|
before do
|
|
subject.extend ExampleHelpers
|
|
# Mock out some infrastructure
|
|
stub_const('Rails::VERSION::MAJOR', 3)
|
|
rswag_config = double('rswag_config')
|
|
allow(rswag_config).to receive(:get_swagger_doc).and_return(global_metadata)
|
|
allow(subject).to receive(:rswag_config).and_return(rswag_config)
|
|
end
|
|
let(:api_metadata) do
|
|
{
|
|
path_item: { template: '/blogs/{blog_id}/comments/{id}' },
|
|
operation: {
|
|
verb: :put,
|
|
summary: 'Updates a blog',
|
|
parameters: [
|
|
{ name: :blog_id, in: :path, type: 'integer' },
|
|
{ name: 'id', in: :path, type: 'integer' },
|
|
{ name: 'q1', in: :query, type: 'string' },
|
|
{ name: :blog, in: :body, schema: { type: 'object' } }
|
|
],
|
|
security: [
|
|
{ api_key: [] }
|
|
]
|
|
}
|
|
}
|
|
end
|
|
let(:global_metadata) do
|
|
{
|
|
securityDefinitions: {
|
|
api_key: {
|
|
type: :apiKey,
|
|
name: 'api_key',
|
|
in: :query
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
describe '#submit_request(api_metadata)' do
|
|
before do
|
|
allow(subject).to receive(:blog_id).and_return(1)
|
|
allow(subject).to receive(:id).and_return(2)
|
|
allow(subject).to receive(:q1).and_return('foo')
|
|
allow(subject).to receive(:api_key).and_return('fookey')
|
|
allow(subject).to receive(:blog).and_return(text: 'Some comment')
|
|
allow(subject).to receive(:put)
|
|
subject.submit_request(api_metadata)
|
|
end
|
|
|
|
it "submits a request built from metadata and 'let' values" do
|
|
expect(subject).to have_received(:put).with(
|
|
'/blogs/1/comments/2?q1=foo&api_key=fookey',
|
|
"{\"text\":\"Some comment\"}",
|
|
{}
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|