diff --git a/spec/components/chapter_picker_component_spec.rb b/spec/components/chapter_picker_component_spec.rb index b6efaf2a1..81ebf2f07 100644 --- a/spec/components/chapter_picker_component_spec.rb +++ b/spec/components/chapter_picker_component_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' -require 'view_component/test_helpers' RSpec.describe ChapterPickerComponent do - include ViewComponent::TestHelpers - let(:chapters) { Fabricate.times(3, :chapter) } it 'renders a text input with datalist attributes' do diff --git a/spec/components/chapters_sidebar_component_spec.rb b/spec/components/chapters_sidebar_component_spec.rb index 73bb65e5a..9a05797be 100644 --- a/spec/components/chapters_sidebar_component_spec.rb +++ b/spec/components/chapters_sidebar_component_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' -require 'view_component/test_helpers' RSpec.describe ChaptersSidebarComponent do - include ViewComponent::TestHelpers include Rails.application.routes.url_helpers let(:chapters) { Fabricate.times(3, :chapter) } diff --git a/spec/components/event_card_component_spec.rb b/spec/components/event_card_component_spec.rb index 9eae9efc2..e5a5a0bd6 100644 --- a/spec/components/event_card_component_spec.rb +++ b/spec/components/event_card_component_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' -require 'view_component/test_helpers' RSpec.describe EventCardComponent, type: :component do - include ViewComponent::TestHelpers let(:chapter) { Fabricate(:chapter, active: true) } context 'with a workshop' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 069b8d2d4..f362e8cdb 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -29,13 +29,16 @@ config.use_transactional_fixtures = true # RSpec Rails can automatically mix in different behaviours based on the - # file location of the spec. This line needs to be present for ViewComponent - # to work with controller specs + # file location of the spec. + # Register the spec/components directory mapping BEFORE inference runs — + # `infer_spec_type_from_file_location!` snapshots DIRECTORY_MAPPINGS at call time. + RSpec::Rails::DIRECTORY_MAPPINGS[:component] = %w[spec components] config.infer_spec_type_from_file_location! - # Connect ViewComponent to RSpec, adding RSpec metadata type: :component. - # This extends Rails' own built-in (e.g. "type: :controller") metadata system. - RSpec::Rails::DIRECTORY_MAPPINGS[:component] = %w[spec/components] + # ViewComponent does not wire its RSpec helpers into RSpec itself (no + # lib/view_component/rspec.rb in v4), so include them for type: :component specs. + require 'view_component/test_helpers' + config.include ViewComponent::TestHelpers, type: :component # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace!