<commit_before>require 'rspec/webservice_matchers/util'

module RSpec
  module WebserviceMatchers
    module RedirectTemporarilyTo
      # Do we get a 302 or 307 to the place we intend?
      RSpec::Matchers.define :redirect_temporarily_to do |expected|
        include RSpec
        error_message = status = actual_location = nil

        match do |url_or_domain_name|
          begin
            status, headers = Util.head(url_or_domain_name)
            actual_location = headers['location']

            Util.temp_redirect?(status) && expected_location?(expected, actual_location)
          rescue Exception => e
            error_message = e.message
            false
          end
        end

        failure_message do
          if !error_message.nil?
            error_message
          else
            mesgs = []
            if Util.permanent_redirect? status
              mesgs << 'received a permanent redirect'
            end
            unless expected_location? expected, actual_location
              mesgs << "received location #{actual_location}"
            end
            unless Util.redirect? status
              mesgs << "not a redirect: received status #{status}"
            end
            mesgs.join('; ').capitalize
          end
        end

        def expected_location?(expected, actual)
          actual =~ %r{#{expected}/?}
        end
      end
    end
  end
end<commit_msg>Cleanup<commit_after>require 'rspec/webservice_matchers/util'

module RSpec
  module WebserviceMatchers
    module RedirectTemporarilyTo
      # Do we get a 302 or 307 to the place we intend?
      RSpec::Matchers.define :redirect_temporarily_to do |expected|
        include RSpec
        error_message = status = actual_location = nil

        match do |url_or_domain_name|
          begin
            status, headers = Util.head(url_or_domain_name)
            actual_location = headers['location']

            Util.temp_redirect?(status) && expected_location?(expected, actual_location)
          rescue Exception => e
            error_message = e.message
            false
          end
        end

        failure_message do
          return error_message if error_message

          error_mesgs = []
          if Util.permanent_redirect? status
            error_mesgs << 'received a permanent redirect'
          end
          unless expected_location? expected, actual_location
            error_mesgs << "received location #{actual_location}"
          end
          unless Util.redirect? status
            error_mesgs << "not a redirect: received status #{status}"
          end
          error_mesgs.join('; ').capitalize
        end

        def expected_location?(expected, actual)
          actual =~ %r{#{expected}/?}
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06771766391974203, 'fraction_numerical': 0.004299534217126478, 'mean_word_length': 1.9205020920502092, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2557003', 'n_tokens_mistral': 732, 'n_tokens_neox': 714, 'n_words': 198}