<commit_before>require 'active_support/test_case'

module ActionView
  class NonInferrableHelperError < ActionViewError
    def initialize(name)
      super "Unable to determine the helper to test from #{name}. " +
        "You'll need to specify it using tests YourHelper in your " +
        "test case definition"
    end
  end

  class TestCase < ActiveSupport::TestCase
    class_inheritable_accessor :helper_class
    @@helper_class = nil

    class << self
      def tests(helper_class)
        self.helper_class = helper_class
      end

      def helper_class
        if current_helper_class = read_inheritable_attribute(:helper_class)
          current_helper_class
        else
          self.helper_class = determine_default_helper_class(name)
        end
      end

      def determine_default_helper_class(name)
        name.sub(/Test$/, '').constantize
      rescue NameError
        raise NonInferrableHelperError.new(name)
      end
    end

    ActionView::Base.helper_modules.each do |helper_module|
      include helper_module
    end
    include ActionController::PolymorphicRoutes
    include ActionController::RecordIdentifier

    setup :setup_with_helper_class

    def setup_with_helper_class
      self.class.send(:include, helper_class)
    end

    class TestController < ActionController::Base
      attr_accessor :request, :response

      def initialize
        @request = ActionController::TestRequest.new
        @response = ActionController::TestResponse.new
      end
    end

    private
      def method_missing(selector, *args)
        controller = TestController.new
        return controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
        super
      end
  end
end
<commit_msg>Don't require AV::TestCases to have a helper class. Only include the helper class in setup if it hasn't been already.<commit_after>require 'active_support/test_case'

module ActionView
  class TestCase < ActiveSupport::TestCase
    class_inheritable_accessor :helper_class
    @@helper_class = nil

    class << self
      def tests(helper_class)
        self.helper_class = helper_class
      end

      def helper_class
        if current_helper_class = read_inheritable_attribute(:helper_class)
          current_helper_class
        else
          self.helper_class = determine_default_helper_class(name)
        end
      end

      def determine_default_helper_class(name)
        name.sub(/Test$/, '').constantize
      rescue NameError
        nil
      end
    end

    ActionView::Base.helper_modules.each do |helper_module|
      include helper_module
    end
    include ActionController::PolymorphicRoutes
    include ActionController::RecordIdentifier

    setup :setup_with_helper_class

    def setup_with_helper_class
      if helper_class && !self.class.ancestors.include?(helper_class)
        self.class.send(:include, helper_class)
      end
    end

    class TestController < ActionController::Base
      attr_accessor :request, :response

      def initialize
        @request = ActionController::TestRequest.new
        @response = ActionController::TestResponse.new
      end
    end

    private
      def method_missing(selector, *args)
        controller = TestController.new
        return controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
        super
      end
  end
end

{'fraction_non_alphanumeric': 0.06447865233807726, 'fraction_numerical': 0.0, 'mean_word_length': 2.9815028901734104, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, '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': '4109993', 'n_tokens_mistral': 932, 'n_tokens_neox': 914, 'n_words': 222}