@@ -16,20 +16,24 @@ def self.call(responses, status, content_type, request_method:, path:)
1616 return Match . new ( error : Failure . new ( :response_not_found , message :) , response : nil )
1717 end
1818 response = FindContent . call ( contents , content_type )
19- if response . nil?
20- message = "#{ content_error ( content_type , request_method :,
21- path :) } Content-Type should be #{ contents . keys . join ( ' or ' ) } ."
22- return Match . new ( error : Failure . new ( :response_not_found , message :) , response : nil )
23- end
19+ return response_not_found ( content_type :, contents :, request_method :, path :) unless response
2420
2521 Match . new ( response :, error : nil )
2622 end
2723
28- def self . content_error ( content_type , request_method :, path :)
29- return 'Response Content-Type must not be empty.' if content_type . nil? || content_type . empty?
30-
31- "Response Content-Type #{ content_type } is not defined for #{ request_method } #{ path } ."
24+ def self . response_not_found ( content_type :, contents :, request_method :, path :)
25+ empty_content = content_type . nil? || content_type . empty?
26+ message =
27+ "Content-Type should be #{ contents . keys . join ( ' or ' ) } , " \
28+ "but was #{ empty_content ? 'empty' : content_type } for " \
29+ "#{ request_method . upcase } #{ path } "
30+
31+ Match . new (
32+ error : Failure . new ( :response_not_found , message :) ,
33+ response : nil
34+ )
3235 end
36+ private_class_method :response_not_found
3337
3438 def self . find_status ( responses , status )
3539 # According to OAS status has to be a string,
0 commit comments