diff --git a/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb b/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb index b537c744526..f5480e5977a 100644 --- a/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb +++ b/admin/spec/components/solidus_admin/layout/navigation/component_spec.rb @@ -34,7 +34,7 @@ it "renders the account nav component" do account_component = mock_component do def call - "account nav" + "account nav".html_safe end end component = described_class.new( diff --git a/admin/spec/support/solidus_admin/component_helpers.rb b/admin/spec/support/solidus_admin/component_helpers.rb index e68d7d37c9d..49833a4687d 100644 --- a/admin/spec/support/solidus_admin/component_helpers.rb +++ b/admin/spec/support/solidus_admin/component_helpers.rb @@ -12,13 +12,14 @@ module ComponentHelpers # end # end def mock_component(&definition) - Class.new(SolidusAdmin::BaseComponent) do - # 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 - def self.name - "Foo" - end - end.tap { |klass| klass.class_eval(&definition) if 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