spec/grape/middleware/formatter_spec.rb in grape-1.7.0 vs spec/grape/middleware/formatter_spec.rb in grape-1.7.1

- old
+ new

@@ -11,11 +11,11 @@ context 'serialization' do let(:body) { { 'abc' => 'def' } } it 'looks at the bodies for possibly serializable data' do _, _, bodies = *subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json') - bodies.each { |b| expect(b).to eq(::Grape::Json.dump(body)) } + bodies.each { |b| expect(b).to eq(::Grape::Json.dump(body)) } # rubocop:disable RSpec/IteratedExpectation end context 'default format' do let(:body) { ['foo'] } @@ -24,11 +24,11 @@ def to_json(*_args) '"bar"' end end - subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('"bar"') } + subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('"bar"') } # rubocop:disable RSpec/IteratedExpectation end end context 'jsonapi' do let(:body) { { 'foos' => [{ 'bar' => 'baz' }] } } @@ -38,11 +38,11 @@ def to_json(*_args) '{"foos":[{"bar":"baz"}] }' end end - subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').to_a.last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') } + subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').to_a.last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') } # rubocop:disable RSpec/IteratedExpectation end end context 'xml' do let(:body) { +'string' } @@ -51,12 +51,11 @@ body.instance_eval do def to_xml '<bar/>' end end - - subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('<bar/>') } + subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('<bar/>') } # rubocop:disable RSpec/IteratedExpectation end end end context 'error handling' do @@ -241,10 +240,11 @@ end end end context 'input' do + content_types = ['application/json', 'application/json; charset=utf-8'].freeze %w[POST PATCH PUT DELETE].each do |method| context 'when body is not nil or empty' do context 'when Content-Type is supported' do let(:io) { StringIO.new('{"is_boolean":true,"string":"thing"}') } let(:content_type) { 'application/json' } @@ -318,10 +318,10 @@ 'CONTENT_LENGTH' => 0 ) end end - ['application/json', 'application/json; charset=utf-8'].each do |content_type| + content_types.each do |content_type| context content_type do it "parses the body from #{method} and copies values into rack.request.form_hash" do io = StringIO.new('{"is_boolean":true,"string":"thing"}') subject.call( 'PATH_INFO' => '/info',