class Capybara::Result

def failure_message

def failure_message
  message = @query.failure_message
  if count.zero?
    message << ' but there were no matches'
  else
    message << ", found #{count} #{Capybara::Helpers.declension('match', 'matches', count)}: " \
            << full_results.map { |r| r.text.inspect }.join(', ')
  end
  unless rest.empty?
    elements = rest.map { |el| el.text rescue '<<ERROR>>' }.map(&:inspect).join(', ') # rubocop:disable Style/RescueModifier
    message << '. Also found ' << elements << ', which matched the selector but not all filters. '
    message << @filter_errors.join('. ') if (rest.size == 1) && count.zero?
  end
  message
end