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
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ bower_components/swagger-ui/*
|
||||
!bower_components/swagger-ui/dist
|
||||
.ruby-version
|
||||
.idea
|
||||
spec/dummy/swagger/v1_api.json
|
||||
@ -28,17 +28,26 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
||||
end
|
||||
end
|
||||
|
||||
def swaggerize(*groups)
|
||||
def run_group_and_send_example_group_finished_notification(*groups)
|
||||
groups.each do |group|
|
||||
group.run(reporter)
|
||||
send_notification_for_all_child_groups group
|
||||
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
|
||||
swagger_root = (Rails.root + 'swagger').to_s
|
||||
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',
|
||||
version: 'v1' } } })
|
||||
allow(RSpec.configuration).to receive(:swagger_root).and_return(swagger_root)
|
||||
@ -48,13 +57,13 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
||||
describe '#new' 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_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
|
||||
|
||||
describe '#example_group_finished' do
|
||||
before do
|
||||
swaggerize(group)
|
||||
run_group_and_send_example_group_finished_notification(group)
|
||||
end
|
||||
|
||||
it "should print 'Generating Swagger Docs ...'" do
|
||||
@ -76,4 +85,51 @@ RSpec.describe ::SwaggerRails::RSpec::Formatter do
|
||||
: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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user