mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Adding test for formatter#stop
This commit is contained in:
parent
2fae4a0a30
commit
d7f02de0c2
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,4 +13,5 @@ bower_components/*
|
|||||||
bower_components/swagger-ui/*
|
bower_components/swagger-ui/*
|
||||||
!bower_components/swagger-ui/dist
|
!bower_components/swagger-ui/dist
|
||||||
.ruby-version
|
.ruby-version
|
||||||
.idea
|
.idea
|
||||||
|
spec/dummy/swagger/v1_api.json
|
||||||
@ -28,19 +28,28 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def swaggerize(*groups)
|
def run_group_and_send_example_group_finished_notification(*groups)
|
||||||
groups.each do |group|
|
groups.each do |group|
|
||||||
group.run(reporter)
|
group.run(reporter)
|
||||||
send_notification_for_all_child_groups group
|
send_notification_for_all_child_groups group
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_group_and_send_stop_notification(*groups)
|
||||||
|
groups.each do |group|
|
||||||
|
group.run(reporter)
|
||||||
|
send_notification_for_all_child_groups group
|
||||||
|
send_notification :stop, stop_notification
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:swagger_root) { (Rails.root + 'swagger').to_s }
|
||||||
|
let(:swagger_doc) { 'v1_api.json' }
|
||||||
before(:each) do
|
before(:each) do
|
||||||
swagger_root = (Rails.root + 'swagger').to_s
|
|
||||||
SwaggerRails::Configuration.new.tap { |c| c.swagger_root = swagger_root }
|
SwaggerRails::Configuration.new.tap { |c| c.swagger_root = swagger_root }
|
||||||
allow(RSpec.configuration).to receive(:swagger_docs).and_return({ 'v1_api.json' => { swagger: '2.0',
|
allow(RSpec.configuration).to receive(:swagger_docs).and_return({ swagger_doc => { swagger: '2.0',
|
||||||
info: { title: 'API V1',
|
info: { title: 'API V1',
|
||||||
version: 'v1' } } })
|
version: 'v1' } } })
|
||||||
allow(RSpec.configuration).to receive(:swagger_root).and_return(swagger_root)
|
allow(RSpec.configuration).to receive(:swagger_root).and_return(swagger_root)
|
||||||
@formatter = SwaggerRails::RSpec::Formatter.new(StringIO.new)
|
@formatter = SwaggerRails::RSpec::Formatter.new(StringIO.new)
|
||||||
end
|
end
|
||||||
@ -48,13 +57,13 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
|||||||
describe '#new' do
|
describe '#new' do
|
||||||
it 'should initialize the swagger_root' do
|
it 'should initialize the swagger_root' do
|
||||||
expect(@formatter.instance_variable_get(:@swagger_root)).to eq((Rails.root + 'swagger').to_s)
|
expect(@formatter.instance_variable_get(:@swagger_root)).to eq((Rails.root + 'swagger').to_s)
|
||||||
expect(@formatter.instance_variable_get(:@swagger_docs)).to eq({"v1_api.json"=>{:swagger=>"2.0", :info=>{:title=>"API V1", :version=>"v1"}}})
|
expect(@formatter.instance_variable_get(:@swagger_docs)).to eq({ swagger_doc => { :swagger => "2.0", :info => { :title => "API V1", :version => "v1" } } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#example_group_finished' do
|
describe '#example_group_finished' do
|
||||||
before do
|
before do
|
||||||
swaggerize(group)
|
run_group_and_send_example_group_finished_notification(group)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print 'Generating Swagger Docs ...'" do
|
it "should print 'Generating Swagger Docs ...'" do
|
||||||
@ -68,12 +77,59 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
|||||||
:info => { :title => 'API V1',
|
:info => { :title => 'API V1',
|
||||||
:version => 'v1' },
|
:version => 'v1' },
|
||||||
:paths => { '/ping' => { :post => { :tags => ['Ping API'],
|
:paths => { '/ping' => { :post => { :tags => ['Ping API'],
|
||||||
:summary => 'checks if site is alive',
|
:summary => 'checks if site is alive',
|
||||||
:description => 'A very long description',
|
:description => 'A very long description',
|
||||||
:consumes => ['application/json'],
|
:consumes => ['application/json'],
|
||||||
:produces => ['application/json'],
|
:produces => ['application/json'],
|
||||||
:parameters => [],
|
:parameters => [],
|
||||||
:responses => { '200' => { :description => '(OK) Site up and running' } } } } } } })
|
:responses => { '200' => { :description => '(OK) Site up and running' } } } } } } })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#stop' do
|
||||||
|
before(:each) do
|
||||||
|
run_group_and_send_stop_notification(group)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should write to swagger doc inside swagger root directory' do
|
||||||
|
file_path = File.join(swagger_root, swagger_doc)
|
||||||
|
file_context= nil
|
||||||
|
|
||||||
|
File.open(file_path, 'r') do |file|
|
||||||
|
file_context = file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(JSON.parse(file_context)).to eq({ 'swagger' => '2.0',
|
||||||
|
'info' => {
|
||||||
|
'title' => 'API V1',
|
||||||
|
'version' => 'v1'
|
||||||
|
},
|
||||||
|
'paths' => {
|
||||||
|
'/ping' => {
|
||||||
|
'post' => {
|
||||||
|
'tags' => [
|
||||||
|
'Ping API'
|
||||||
|
],
|
||||||
|
'summary' => 'checks if site is alive',
|
||||||
|
'description' => 'A very long description',
|
||||||
|
'consumes' => [
|
||||||
|
'application/json'
|
||||||
|
],
|
||||||
|
'produces' => [
|
||||||
|
'application/json'
|
||||||
|
],
|
||||||
|
'parameters' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
'responses' => {
|
||||||
|
'200' => {
|
||||||
|
'description' => '(OK) Site up and running'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user