<commit_before>require "spec_helper"

module RSpec::Rails
  describe HelperExampleGroup do
    module ::FoosHelper
      class InternalClass
      end
    end

    subject { HelperExampleGroup }

    it_behaves_like "an rspec-rails example group mixin", :helper,
      './spec/helpers/', '.\\spec\\helpers\\'

    it "provides a controller_path based on the helper module's name" do
      example = double
      allow(example).to receive_message_chain(:example_group, :described_class) { FoosHelper }

      helper_spec = Object.new.extend HelperExampleGroup
      expect(helper_spec.__send__(:_controller_path, example)).to eq("foos")
    end

    describe "#helper" do
      it "returns the instance of AV::Base provided by AV::TC::Behavior" do
        helper_spec = Object.new.extend HelperExampleGroup
        expect(helper_spec).to receive(:view_assigns)
        av_tc_b_view = double('_view')
        expect(av_tc_b_view).to receive(:assign)
        allow(helper_spec).to receive(:_view) { av_tc_b_view }
        expect(helper_spec.helper).to eq(av_tc_b_view)
      end

      before do
        Object.const_set(:ApplicationHelper, Module.new)
      end

      after do
        Object.__send__(:remove_const, :ApplicationHelper)
      end

      it "includes ApplicationHelper" do
        group = RSpec::Core::ExampleGroup.describe do
          include HelperExampleGroup
          def _view
            if ActionView::Base.respond_to?(:empty)
              ActionView::Base.empty
            else
              ActionView::Base.new
            end
          end
        end
        expect(group.new.helper).to be_kind_of(ApplicationHelper)
      end
    end
  end

  describe HelperExampleGroup::ClassMethods do
    describe "determine_default_helper_class" do
      let(:group) do
        RSpec::Core::ExampleGroup.describe do
          include HelperExampleGroup
        end
      end

      context "the described is a module" do
        it "returns the module" do
          allow(group).to receive(:described_class) { FoosHelper }
          expect(group.determine_default_helper_class("ignore this")).
            to eq(FoosHelper)
        end
      end
<commit_msg>Use dynamic method definition instead of basic if/else flow<commit_after>require "spec_helper"

module RSpec::Rails
  describe HelperExampleGroup do
    module ::FoosHelper
      class InternalClass
      end
    end

    subject { HelperExampleGroup }

    it_behaves_like "an rspec-rails example group mixin", :helper,
      './spec/helpers/', '.\\spec\\helpers\\'

    it "provides a controller_path based on the helper module's name" do
      example = double
      allow(example).to receive_message_chain(:example_group, :described_class) { FoosHelper }

      helper_spec = Object.new.extend HelperExampleGroup
      expect(helper_spec.__send__(:_controller_path, example)).to eq("foos")
    end

    describe "#helper" do
      it "returns the instance of AV::Base provided by AV::TC::Behavior" do
        helper_spec = Object.new.extend HelperExampleGroup
        expect(helper_spec).to receive(:view_assigns)
        av_tc_b_view = double('_view')
        expect(av_tc_b_view).to receive(:assign)
        allow(helper_spec).to receive(:_view) { av_tc_b_view }
        expect(helper_spec.helper).to eq(av_tc_b_view)
      end

      before do
        Object.const_set(:ApplicationHelper, Module.new)
      end

      after do
        Object.__send__(:remove_const, :ApplicationHelper)
      end

      it "includes ApplicationHelper" do
        group = RSpec::Core::ExampleGroup.describe do
          include HelperExampleGroup
          if ActionView::Base.respond_to?(:empty)
            def _view
              ActionView::Base.empty
            end
          else
            def _view
              ActionView::Base.new
            end
          end
        end
        expect(group.new.helper).to be_kind_of(ApplicationHelper)
      end
    end
  end

  describe HelperExampleGroup::ClassMethods do
    describe "determine_default_helper_class" do
      let(:group) do
        RSpec::Core::ExampleGroup.describe do
          include HelperExampleGroup
        end
      end

      context "the described is a module" do
        it "returns the module" do
          allow(group).to receive(:described_class) { FoosHelper }
          expect(group.determine_default_helper_class("ignore this")).
            to eq(FoosHelper)
        end
      end

{'fraction_non_alphanumeric': 0.08183047790802525, 'fraction_numerical': 0.0, 'mean_word_length': 2.4854673998428907, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6884420', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1234, 'n_words': 301}