Skip to content

test: wire ViewComponent RSpec helpers via type metadata - #2828

Merged
olleolleolle merged 1 commit into
masterfrom
feature/component-spec-helpers-via-metadata
Aug 31, 2026
Merged

test: wire ViewComponent RSpec helpers via type metadata#2828
olleolleolle merged 1 commit into
masterfrom
feature/component-spec-helpers-via-metadata

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Follow-up to #2820, addressing Olle's comment: component specs should get ViewComponent::TestHelpers via RSpec type metadata instead of requiring and including it by hand.

While checking, we found that path-based inference for type: :component never actually worked in this repo. infer_spec_type_from_file_location! iterates DIRECTORY_MAPPINGS at call time, but spec/rails_helper.rb registered the :component mapping only on the following line. event_card_component_spec masked the problem by declaring type: :component explicitly (the view_component generator adds it); the other two component specs patched over the missing helpers with a manual require + include.

Changes

  • spec/rails_helper.rb: register DIRECTORY_MAPPINGS[:component] before calling infer_spec_type_from_file_location!, and include ViewComponent::TestHelpers once for type: :component specs. ViewComponent 4.x no longer ships its own RSpec auto-wiring (no lib/view_component/rspec.rb), so this belongs here.
  • spec/components/*: drop the per-spec require 'view_component/test_helpers' and include ViewComponent::TestHelpers boilerplate.

Net −4 lines. All 16 component spec examples pass; rubocop clean.

`infer_spec_type_from_file_location!` iterates DIRECTORY_MAPPINGS at
call time, but rails_helper registered the `:component` mapping only on
the following line, so `spec/components` specs never got `type:
:component` metadata from their location. `event_card_component_spec`
masked this by declaring the type explicitly; the other two component
specs worked around the missing helpers by requiring and including
`ViewComponent::TestHelpers` by hand.

Register the mapping before inference and include TestHelpers once for
`type: :component` specs. ViewComponent 4.x no longer ships its own
RSpec auto-wiring (no lib/view_component/rspec.rb), so this belongs in
rails_helper. Drop the per-spec boilerplate.
@mroderick
mroderick requested a review from olleolleolle August 31, 2026 08:58
@mroderick
mroderick marked this pull request as ready for review August 31, 2026 08:58

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you!

@olleolleolle
olleolleolle merged commit a17b0e2 into master Aug 31, 2026
10 checks passed
@olleolleolle
olleolleolle deleted the feature/component-spec-helpers-via-metadata branch August 31, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants