Skip to content

Commit 20f1967

Browse files
committed
Refactor OPTIONS specs for route.
1 parent d721c5d commit 20f1967

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

spec/grape/api_spec.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,38 @@ def subject.enable_root_route!
537537
expect(last_response.headers['Content-Type']).to eql 'text/plain'
538538
end
539539

540-
it 'adds an OPTIONS route that returns a 204, an Allow header and a X-Custom-Header' do
541-
subject.before { header 'X-Custom-Header', 'foo' }
542-
subject.get 'example' do
543-
'example'
540+
describe 'adds an OPTIONS route that' do
541+
before do
542+
subject.before { header 'X-Custom-Header', 'foo' }
543+
subject.get 'example' do
544+
'example'
545+
end
546+
options '/example'
547+
end
548+
549+
it 'returns a 204' do
550+
expect(last_response.status).to eql 204
551+
end
552+
553+
it 'has an empty body' do
554+
expect(last_response.body).to be_blank
555+
end
556+
557+
it 'has an Allow header' do
558+
expect(last_response.headers['Allow']).to eql 'OPTIONS, GET, HEAD'
559+
end
560+
561+
it 'has a X-Custom-Header' do
562+
expect(last_response.headers['X-Custom-Header']).to eql 'foo'
563+
end
564+
565+
it 'has no Content-Type' do
566+
expect(last_response.content_type).to be_nil
567+
end
568+
569+
it 'has no Content-Length' do
570+
expect(last_response.content_length).to be_nil
544571
end
545-
options '/example'
546-
expect(last_response.status).to eql 204
547-
expect(last_response.body).to eql ''
548-
expect(last_response.headers['Allow']).to eql 'OPTIONS, GET, HEAD'
549-
expect(last_response.headers['X-Custom-Header']).to eql 'foo'
550572
end
551573

552574
it 'allows HEAD on a GET request' do

0 commit comments

Comments
 (0)