module ViewComponentExampleGroup
  extend ActiveSupport::Concern
  include RSpec::Rails::RailsExampleGroup
  include ActionView::TestCase::Behavior
  include Capybara::RSpecMatchers

  included do
    attr_reader :rendered
  end

  def arbre
    Arbre::Context.new({}, _view)
  end

  def helper
    _view
  end

  def render(*args)
    @rendered = arbre.send(described_class.builder_method_name, *args)
  end
end

RSpec.configure do |config|
  config.include(ViewComponentExampleGroup,
                 :example_group => lambda { |example_group, metadata|
                   %r(spec/views/components) =~ example_group[:file_path]
                 })
end

module ViewComponentExampleGroup
  extend ActiveSupport::Concern
  include RSpec::Rails::RailsExampleGroup
  include ActionView::TestCase::Behavior
  include Capybara::RSpecMatchers

  included do
    attr_reader :rendered
  end

  def arbre(&block)
    Arbre::Context.new({}, _view, &block)
  end

  def helper
    _view
  end

  def render(*args, &block)
    @rendered =
      if block_given?
        arbre(&block).to_s
      else
        arbre.send(described_class.builder_method_name, *args, &block)
      end
  end
end

RSpec.configure do |config|
  config.include(ViewComponentExampleGroup,
                 :example_group => lambda { |example_group, metadata|
                   %r(spec/views/components) =~ example_group[:file_path]
                 })
end

Allow rendering an Arbre fragment in view component tests
Allow rendering an Arbre fragment in view component tests
