Sha256: 95e72a1b7d4f06098f2e5169ce489306fea3a9f0f81cb0650241a5a266cbe2db
Contents?: true
Size: 957 Bytes
Versions: 3
Compression:
Stored size: 957 Bytes
Contents
# frozen_string_literal: true module SolidusAdmin module TestingSupport module ComponentHelpers # Mocks a component class with the given definition. # # @param definition [Proc] the component definition # @example # mock_component do # def call # "Rendered" # end # end def mock_component(&definition) location = caller(1, 1).first component_class = Class.new(SolidusAdmin::BaseComponent) # ViewComponent will complain if we don't fake a class name: # @see https://github.com/ViewComponent/view_component/blob/5decd07842c48cbad82527daefa3fe9c65a4226a/lib/view_component/base.rb#L371 component_class.define_singleton_method(:name) { "Foo" } component_class.define_singleton_method(:to_s) { "#{name} (#{location})" } component_class.class_eval(&definition) if definition component_class end end end end
Version data entries
3 entries across 3 versions & 1 rubygems