Skip to content

Commit 1070aed

Browse files
committed
refactor: remove unnecessary super() call and add RSpec directory mapping for components
Based on review feedback from olleolleolle: - Remove unnecessary super() call from ViewComponent initialize - Add RSpec::Rails::DIRECTORY_MAPPINGS to auto-infer type: :component - Remove explicit type: :component from component spec (now inferred)
1 parent 80f169e commit 1070aed

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

app/components/chapters_sidebar_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
class ChaptersSidebarComponent < ViewComponent::Base
4-
def initialize(chapters:, title: nil)
5-
super()
4+
# ViewComponent::Base does not define initialize, so super is not needed
5+
def initialize(chapters:, title: nil) # rubocop:disable Lint/MissingSuper
66
@chapters = chapters
77
@title = title
88
end

spec/components/chapters_sidebar_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22
require 'view_component/test_helpers'
33

4-
RSpec.describe ChaptersSidebarComponent, type: :component do
4+
RSpec.describe ChaptersSidebarComponent do
55
include ViewComponent::TestHelpers
66
include Rails.application.routes.url_helpers
77

spec/rails_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# to work with controller specs
3434
config.infer_spec_type_from_file_location!
3535

36+
# Connect ViewComponent to RSpec, adding RSpec metadata type: :component.
37+
# This extends Rails' own built-in (e.g. "type: :controller") metadata system.
38+
RSpec::Rails::DIRECTORY_MAPPINGS[:component] = %w[spec/components]
39+
3640
# Filter lines from Rails gems in backtraces.
3741
config.filter_rails_from_backtrace!
3842
# arbitrary gems may also be filtered from backtraces

0 commit comments

Comments
 (0)