lib/rspec/rails/api/dsl/example.rb in rspec-rails-api-0.7.0 vs lib/rspec/rails/api/dsl/example.rb in rspec-rails-api-0.8.0

- old
+ new

@@ -64,22 +64,23 @@ # # @param response [ActionDispatch::TestResponse] The response # @param expected_code [Number] Code to test for # @param ignore_content_type [Boolean] Whether to ignore the response's content-type for # this response only - def check_response(response, expected_code, ignore_content_type: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity + def check_response(response, expected_code, ignore_content_type: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity code_error_message = if response.status != expected_code && response.status == 422 <<~TXT expected: #{expected_code} got: #{response.status} response: #{response.body} TXT end expect(response.status).to eq(expected_code), code_error_message if expected_code != 204 && !ignore_content_type - expect(response.headers['Content-Type'].downcase).to eq 'application/json; charset=utf-8' + content_type = rra_current_example[:expectations][:content_type] || RSpec::Rails::Api::Metadata.default_expected_content_type # rubocop:disable Layout/LineLength + expect(response.headers['Content-Type'].downcase).to eq content_type end expectations = rra_current_example[:expectations] expect(response).to have_many defined(expectations[:many]) if expectations[:many] expect(response).to have_one defined(expectations[:one]) if expectations[:one] expect(response.body).to eq '' if expectations[:none] @@ -152,10 +153,10 @@ end # Use everything else in query string uri = URI.parse(url) query_params = request_params.select { |k| used_path_params.exclude? k } - uri.query = URI.encode_www_form(query_params) unless query_params.blank? + uri.query = URI.encode_www_form(query_params) if query_params.present? uri.to_s end ##