spec/praxis/response_definition_spec.rb in praxis-0.20.1 vs spec/praxis/response_definition_spec.rb in praxis-0.21
- old
+ new
@@ -446,11 +446,11 @@
describe '#validate_parts!' do
context 'with legacy multipart response' do
subject(:response) { Praxis::Responses::Ok.new(status: response_status, headers: response_headers) }
- let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, 'Content-Type' => 'application/special'}) }
+ let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, 'Content-Type' => 'application/special'},{}) }
before do
response_definition.parts like: :ok, media_type: 'application/special'
response.add_part(part)
end
@@ -461,11 +461,11 @@
response_definition.validate_parts!(response)
}.to_not raise_error
end
context 'with invalid part' do
- let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, "Location" => "somewhere"}) }
+ let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, "Location" => "somewhere"},{}) }
it 'validates' do
expect {
response_definition.validate_parts!(response)
}.to raise_error(Praxis::Exceptions::Validation)
@@ -518,18 +518,30 @@
end
its([:name]) { should eq 'Instance' }
context 'examples' do
subject(:examples) { payload[:examples] }
- its(['json', :content_type]) { 'application/vnd.acme.instance+json '}
- its(['xml', :content_type]) { 'application/vnd.acme.instance+xml' }
+ its(['json', :content_type]) { should eq('application/vnd.acme.instance+json') }
+ its(['xml', :content_type]) { should eq('application/vnd.acme.instance+xml') }
it 'properly encodes the example bodies' do
json = Praxis::Application.instance.handlers['json'].parse(examples['json'][:body])
xml = Praxis::Application.instance.handlers['xml'].parse(examples['xml'][:body])
expect(json).to eq xml
end
+ end
+
+ context 'which does not have a identifier' do
+ subject(:examples) { payload[:examples] }
+ before do
+ allow(response.media_type).to receive(:identifier).and_return(nil)
+ end
+
+ it 'still renders examples but as pure handler types for contents' do
+ expect(subject['json'][:content_type]).to eq('application/json')
+ expect(subject['xml'][:content_type]).to eq('application/xml')
+ end
end
end