spec/lib/oapi_tasks_spec.rb in grape-swagger-1.4.2 vs spec/lib/oapi_tasks_spec.rb in grape-swagger-1.5.0

- old
+ new

@@ -23,10 +23,13 @@ end end subject { described_class.new(Api::Base) } + let(:api_class) { subject.send(:api_class) } + let(:docs_url) { subject.send(:urls_for, api_class).first } + describe '.new' do it 'accepts class name as a constant' do expect(described_class.new(::Api::Base).send(:api_class)).to eq(Api::Base) end @@ -36,11 +39,11 @@ end describe '#make_request' do describe 'complete documentation' do before do - subject.send(:make_request) + subject.send(:make_request, docs_url) end describe 'not storing' do it 'has no error' do expect(subject.send(:error?)).to be false @@ -49,11 +52,11 @@ it 'does not allow to save' do expect(subject.send(:save_to_file?)).to be false end it 'requests doc url' do - expect(subject.send(:url_for)).to eql '/api/swagger_doc' + expect(docs_url).to eql '/api/swagger_doc' end end describe 'store it' do before { ENV['store'] = 'true' } @@ -66,14 +69,18 @@ end describe 'documentation for resource' do before do ENV['resource'] = resource - subject.send(:make_request) + subject.send(:make_request, docs_url) end - let(:response) { JSON.parse(subject.send(:make_request)) } + let(:response) do + JSON.parse( + subject.send(:make_request, docs_url) + ) + end after { ENV.delete('resource') } describe 'valid name' do let(:resource) { 'otherItem' } @@ -81,11 +88,11 @@ it 'has no error' do expect(subject.send(:error?)).to be false end it 'requests doc url' do - expect(subject.send(:url_for)).to eql "/api/swagger_doc/#{resource}" + expect(docs_url).to eql "/api/swagger_doc/#{resource}" end it 'has only one resource path' do expect(response['paths'].length).to eql 1 expect(response['paths'].keys.first).to end_with resource @@ -113,11 +120,11 @@ end end describe 'call it' do before do - subject.send(:make_request) + subject.send(:make_request, docs_url) end specify do expect(subject).to respond_to :oapi expect(subject.oapi).to be_a String expect(subject.oapi).not_to be_empty @@ -126,30 +133,30 @@ end describe '#file' do describe 'no store given' do it 'returns swagger_doc.json' do - expect(subject.send(:file)).to end_with 'swagger_doc.json' + expect(subject.send(:file, docs_url)).to end_with 'swagger_doc.json' end end describe 'store given' do after { ENV.delete('store') } describe 'boolean true' do before { ENV['store'] = 'true' } it 'returns swagger_doc.json' do - expect(subject.send(:file)).to end_with 'swagger_doc.json' + expect(subject.send(:file, docs_url)).to end_with 'swagger_doc.json' end end describe 'name given' do let(:name) { 'oapi_doc.json' } before { ENV['store'] = name } it 'returns swagger_doc.json' do - expect(subject.send(:file)).to end_with name + expect(subject.send(:file, docs_url)).to include(name.split('.')[0]) end end end end end