<commit_before>describe "Fortitude helper support", :type => :system do
  before :each do
    @output_buffer = ""
    @output_buffer_holder_class = Class.new do
      attr_accessor :output_buffer
    end
    @output_buffer_holder = @output_buffer_holder_class.new
    @output_buffer_holder.output_buffer = @output_buffer

    @helpers_class = Class.new do
      attr_accessor :output_buffer_holder

      def helper1
        "this is helper1"
      end

      def helper2(input)
        "this is #{input} helper2"
      end

      def helper3(input)
        output_buffer << "this is #{input} helper3"
      end

      def helper4(arg)
        result = yield(arg)
        "foo #{result} bar"
      end

      def p(input)
        "pp#{input}pp"
      end

      def kaboom
        raise "kaboom!"
      end

      def output_buffer
        @output_buffer_holder.output_buffer
      end
    end

    @helpers_object = @helpers_class.new
    @helpers_object.output_buffer_holder = @output_buffer_holder
  end

  def render(widget_or_class, options = { })
    @output_buffer.clear
    super(widget_or_class, { :rendering_context => rc(
      :helpers_object => @helpers_object, :output_buffer_holder => @output_buffer_holder) }.merge(options))
  end

  describe "manual invocation of helpers using #invoke_helper" do
    it "should work for a very simple helper, without arguments" do
      expect(render(widget_class_with_content { s = invoke_helper(:helper1); text s })).to eq("this is helper1")
    end

    it "should allow passing arguments" do
      expect(render(widget_class_with_content { s = invoke_helper(:helper2, 'foo'); text s })).to eq("this is foo helper2")
    end

    it "should work even if automatic_helper_access is off" do
      wc = widget_class do
        automatic_helper_access false
        def content
          text invoke_helper(:helper1)
        end
      end

      expect(render(wc)).to eq("this is helper1")
    end

    it "should allow passing a block" do
      expect(render(widget_class_with_content { text invoke_helper(:helper4, "b") { |a| "x#{a}x" } })).to eq("foo xbx bar")
    end

    it "should return an exception properly" do
      expect { render(widget_class_with_content { invoke_helper(:kaboom) }) }.to raise_error(/kaboom!/i)<commit_msg>Fix helpers_system_spec for 1.8.7.<commit_after>describe "Fortitude helper support", :type => :system do
  before :each do
    @output_buffer = ""
    @output_buffer_holder_class = Class.new do
      attr_accessor :output_buffer
    end
    @output_buffer_holder = @output_buffer_holder_class.new
    @output_buffer_holder.output_buffer = @output_buffer

    @helpers_class = Class.new do
      attr_accessor :output_buffer_holder

      def helper1
        "this is helper1"
      end

      def helper2(input)
        "this is #{input} helper2"
      end

      def helper3(input)
        output_buffer << "this is #{input} helper3"
      end

      def helper4(arg)
        result = yield(arg)
        "foo #{result} bar"
      end

      def p(input)
        "pp#{input}pp"
      end

      def kaboom
        raise "kaboom!"
      end

      def output_buffer
        @output_buffer_holder.output_buffer
      end
    end

    @helpers_object = @helpers_class.new
    @helpers_object.output_buffer_holder = @output_buffer_holder
  end

  def render(widget_or_class, options = { })
    @output_buffer.replace("")
    super(widget_or_class, { :rendering_context => rc(
      :helpers_object => @helpers_object, :output_buffer_holder => @output_buffer_holder) }.merge(options))
  end

  describe "manual invocation of helpers using #invoke_helper" do
    it "should work for a very simple helper, without arguments" do
      expect(render(widget_class_with_content { s = invoke_helper(:helper1); text s })).to eq("this is helper1")
    end

    it "should allow passing arguments" do
      expect(render(widget_class_with_content { s = invoke_helper(:helper2, 'foo'); text s })).to eq("this is foo helper2")
    end

    it "should work even if automatic_helper_access is off" do
      wc = widget_class do
        automatic_helper_access false
        def content
          text invoke_helper(:helper1)
        end
      end

      expect(render(wc)).to eq("this is helper1")
    end

    it "should allow passing a block" do
      expect(render(widget_class_with_content { text invoke_helper(:helper4, "b") { |a| "x#{a}x" } })).to eq("foo xbx bar")
    end

    it "should return an exception properly" do
      expect { render(widget_class_with_content { invoke_helper(:kaboom) }) }.to raise_error(/kaboom!/i)
{'fraction_non_alphanumeric': 0.09367528798087373, 'fraction_numerical': 0.006737665724842426, 'mean_word_length': 2.9366980325064156, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4132782', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1405, 'n_words': 380}