<commit_before>module Assert
  module Helpers

    # when Assert is required it will automatically require in two helper files
    # if they exist:
    # * "./test/helper.rb - package-specific helpers
    # * ~/.assert.rb - user-specific helpers (options, view, etc...)
    # the user-specific helper file will always be required in after the
    # package-specific one

    class << self

      # assume the test dir path is ./test and look for helpers in ./test/helper.rb
      PACKAGE_TEST_DIR = "test"
      PACKAGE_HELPER_FILE = "helper"
      TEST_REGEX = /^#{PACKAGE_TEST_DIR}$|^#{PACKAGE_TEST_DIR}\/|\/#{PACKAGE_TEST_DIR}\/|\/#{PACKAGE_TEST_DIR}$/

      USER_TEST_HELPER = "~/.assert/options"

      def load(caller_info)
        if (crp = caller_root_path(caller_info))
          require_package_test_helper(crp)
        end
        require_user_test_helper
      end

      private

      def require_user_test_helper
        begin
          require File.expand_path(USER_TEST_HELPER)
        rescue LoadError => err
          # do nothing
        end
      end

      # require the package's test/helper file if it exists
      def require_package_test_helper(root_path)
        begin
          require package_helper_file(root_path)
        rescue LoadError => err
          warn err.message
        end
      end

      def package_helper_file(root_path)
        File.join(root_path, PACKAGE_TEST_DIR, PACKAGE_HELPER_FILE+'.rb')
      end

      # this method inspects the caller info and finds the caller's root path
      # this expects the caller's root path to be the parent dir of the first
      # parent dir of caller named TEST_DIR
      def caller_root_path(caller_info)
        caller_dirname = File.expand_path(File.dirname(caller_info[0]))
        test_dir_pos = caller_dirname.index(TEST_REGEX)
        if test_dir_pos && (test_dir_pos > 0)
          caller_dirname[0..(test_dir_pos-1)]
        end
      end
    end

  end<commit_msg>change helpers constants to class methods so we can overwrite them in assert-rails<commit_after>module Assert
  module Helpers

    # when Assert is required it will automatically require in two helper files
    # if they exist:
    # * "./test/helper.rb - package-specific helpers
    # * ~/.assert.rb - user-specific helpers (options, view, etc...)
    # the user-specific helper file will always be required in after the
    # package-specific one

    class << self

      USER_TEST_HELPER = "~/.assert/options"
      
      # assume the test dir path is ./test and look for helpers in ./test/helper.rb
      def package_test_dir
        "test"
      end
      def package_helper_name
        "helper"
      end
      def package_test_helper_regex
        /^#{package_test_dir}$|^#{package_test_dir}\/|\/#{package_test_dir}\/|\/#{package_test_dir}$/
      end

      def load(caller_info)
        if (crp = caller_root_path(caller_info))
          require_package_test_helper(crp)
        end
        require_user_test_helper
      end

      private

      def require_user_test_helper
        begin
          require File.expand_path(USER_TEST_HELPER)
        rescue LoadError => err
          # do nothing
        end
      end

      # require the package's test/helper file if it exists
      def require_package_test_helper(root_path)
        begin
          require package_helper_file(root_path)
        rescue LoadError => err
          warn err.message
        end
      end

      def package_helper_file(root_path)
        File.join(root_path, package_test_dir, package_helper_name + '.rb')
      end

      # this method inspects the caller info and finds the caller's root path
      # this expects the caller's root path to be the parent dir of the first
      # parent dir of caller named TEST_DIR
      def caller_root_path(caller_info)
        caller_dirname = File.expand_path(File.dirname(caller_info[0]))
        test_dir_pos = caller_dirname.index(package_test_helper_regex)
        if test_dir_pos && (test_dir_pos > 0)
          caller_dirname[0..(test_dir_pos-1)]
        end
      end
    end

  end
{'fraction_non_alphanumeric': 0.07479833781471523, 'fraction_numerical': 0.001955512099731117, 'mean_word_length': 2.3846153846153846, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1524465', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1198, 'n_words': 336}