<commit_before>require 'rspec/rails'

module Rafters::ComponentExampleGroup
  extend ActiveSupport::Concern
  include RSpec::Rails::RailsExampleGroup

  included do
    metadata[:type] = :component

    controller do
      # Empty controller
    end

    let(:identifier) { described_class.to_s.underscore }
    let(:options) { Hash.new }

    subject do
      described_class.new(identifier, options).tap do |s|
        s.controller = controller
      end
    end

    let(:controller) do
      example.metadata[:controller].new.tap do |s|
        s.stub(:params).and_return({})
      end
    end

    let(:renderer) do
      Rafters::Renderer.new(controller, controller.view_context)
    end

    let(:page) do
      Capybara.string(renderer.render(subject))
    end
  end

  module ClassMethods
    def controller(base_class = nil, &body)
      base_class ||= ApplicationController

      metadata[:controller] ||= Class.new(base_class) do
        def self.name; "AnonymousController"; end
      end

      metadata[:controller].class_eval(&body)
    end
  end
end<commit_msg>Fix the rspec example group<commit_after>require 'rspec/rails'

module Rafters::ComponentExampleGroup
  extend ActiveSupport::Concern
  include RSpec::Rails::RailsExampleGroup

  included do
    metadata[:type] = :component

    subject do
      described_class.new(described_class.name, {}).tap do |component|
        component.controller = controller
      end
    end
  end

  def controller
    @controller ||= example.metadata[:controller].new.tap do |controller|
      controller.request = ActionController::TestRequest.new
      controller.response = ActionController::TestResponse.new
      controller.params = example.metadata[:params] || HashWithIndifferentAccess.new
    end
  end

  module ClassMethods
    def controller(base_class = nil, &body)
      base_class ||= ApplicationController

      metadata[:controller] ||= Class.new(base_class) do
        def self.name; "AnonymousController"; end
      end

      metadata[:controller].class_eval(&body)
    end

    def params(params = {})
      metadata[:params] ||= params
    end
  end
end
{'fraction_non_alphanumeric': 0.09929742388758782, 'fraction_numerical': 0.0, 'mean_word_length': 3.238095238095238, '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': '3303633', 'n_tokens_mistral': 621, 'n_tokens_neox': 594, 'n_words': 135}