inertia-rails-testing
Test Inertia Rails controller actions with RSpec matchers that verify rendered components, props, flash messages, and deferred data. Always use matchers like `render_component` and `have_props` instead of direct property access, and remember to call `follow_redirect!` after POST/PATCH/DELETE before asserting flash or props.
inertia-rails-testing provides RSpec matchers to verify Inertia component renders, props, and flash messages in controller specs.
AI-generated summary based on this skill's SKILL.md
Install
inertia-rails/skills/inertia-rails-testing
git clone https://github.com/inertia-rails/skills
cp -r skills/skills/inertia-rails-testing ~/.claude/skills/inertia-rails-testingnpx skillfed install inertia-rails/skills/inertia-rails-testingFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I test Inertia Rails components with RSpec matchers?
inertia-rails-testing uses RSpec matchers to verify Inertia responses. Use `render_component` to assert which component was rendered, `have_props` to check passed props, and `have_flash` for flash messages. Always prefer matchers over direct property access: `expect(response).to render_component('Users/Index').with_props(count: 42)` instead of manually inspecting response data.
What's the correct way to test RSpec matchers for Inertia responses?
inertia-rails-testing provides matchers like `render_component`, `have_props`, and `have_flash` for request specs. Chain them to verify component name, passed props, and flash messages in a single assertion. Example: `expect(response).to render_component('Dashboard').with_props(user: @user).and_have_flash('success', 'Saved')`. These matchers replace manual JSON inspection.
How do I handle POST/PATCH/DELETE redirects in Inertia testing?
inertia-rails-testing requires calling `follow_redirect!` after POST, PATCH, or DELETE requests before asserting props or flash. The mutation endpoints redirect to a GET page; without following, you'll inspect the redirect response, not the target page. Example: `post '/users', params: {...}; follow_redirect!; expect(response).to have_flash('success')`.
How can I test deferred props and partial reload behavior?
inertia-rails-testing supports testing deferred props by verifying they appear in the response with lazy-load metadata. Use matchers to inspect the props structure and confirm deferred keys are present. For partial reloads, pass the `X-Inertia-Partial-Data` header in your request spec to simulate client-side partial updates, then assert only the specified props are returned.
What are the key testing patterns for Inertia Rails controller actions?
inertia-rails-testing establishes patterns: use `render_component` to verify the rendered component name, chain `with_props` to assert prop values, call `follow_redirect!` after mutations, and use `have_flash` for flash assertions. Avoid accessing response JSON directly; matchers provide clearer, more maintainable specs that document intent and catch regressions.
Can I convert RSpec patterns to Minitest for Inertia testing?
inertia-rails-testing is primarily RSpec-focused, but Minitest users can write custom assertions or use gems that bridge RSpec matchers. The core patterns—verifying component names, props, and flash—remain the same; only the assertion syntax changes. Consider using `assert_equal` on parsed response JSON or adopting RSpec alongside Minitest for integration tests.
SKILL.md
rendered from the published skill — quoted content, verbatim
Inertia Rails Testing
Testing patterns for Inertia responses with RSpec and Minitest.
For each controller action, verify:
- Correct component → render_component('users/index')
- Expected props → have_props(users: satisfy { ... })
- No leaked data → have_no_prop(:secret)
- Flash messages → follow_redirect! then have_flash(notice: '...')
- Deferred props → have_deferred_props(:analytics)
Common mistake: Forgetting follow_redirect! after PRG — without it, you're
asserting against the 302 redirect
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 2 files
skills/inertia-rails-testing/SKILL.md
skills/inertia-rails-testing/references/minitest.md