inertia-rails/skills

inertia-rails-testing

>- Testing Inertia Rails responses with RSpec and Minitest: component assertions, prop matching, flash verification, deferred props, and partial reload helpers. Use when writing controller specs, request specs, or integration tests for Inertia pages. ALWAYS use matchers (render_component, have_props, have_flash), NOT direct access (inertia.component, inertia.props). CRITICAL: after POST/PATCH/DELETE with redirect, MUST call follow_redirect! before asserting flash or props — without it you're as…

First seen Feb 13, 2026

Installation

$ npx skills add inertia-rails/skills --skill inertia-rails-testing

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from inertia-rails/skills · top by installs.

npx skills add inertia-rails/skills

Browse all from inertia-rails/skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 67
License LICENSE
Default branch main
Open issues 0
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 6,287 B
  • docs SUMMARY.md 611 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 419 installs

SKILL.md

Inertia Rails Testing

Testing patterns for Inertia responses with RSpec and Minitest.

For each controller action, verify:

  • Correct componentrender_component('users/index')
  • Expected propshave_props(users: satisfy { ... })
  • No leaked datahavenoprop(:secret)
  • Flash messagesfollowredirect! then haveflash(notice: '...')
  • Deferred propshavedeferredprops(:analytics)

Common mistake: Forgetting follow_redirect! after PRG — without it, you're asserting against the 302 redirect response, not the Inertia page that follows.

Setup

# spec/rails_helper.rb
require 'inertia_rails/rspec'

RSpec Matchers

Matcher Purpose
beinertiaresponse Verify response is Inertia format
render_component('path') Check rendered component name
have_props(key: value) Partial props match
haveexactprops(key: value) Exact props match
havenoprop(:key) Assert prop absent
have_flash(key: value) Partial flash match
haveexactflash(key: value) Exact flash match
havenoflash(:key) Assert flash absent
havedeferredprops(:key) Check deferred props exist
haveviewdata(key: value) Partial view_data match

RSpec Examples

ALWAYS use matchers (rendercomponent, haveprops, have_flash) instead of direct property access (inertia.component, inertia.props[:key]):

# BAD — direct property access:
# expect(inertia.component).to eq('users/index')
# expect(inertia.props[:users].length).to eq(3)

# GOOD — use matchers:
expect(inertia).to render_component('users/index')
expect(inertia).to have_props(users: satisfy { |u| u.length == 3 })
# Key pattern: follow_redirect! after POST/PATCH/DELETE before asserting
it 'redirects with flash on success' do
  post users_path, params: { user: valid_params }

  expect(response).to redirect_to(users_path)
  follow_redirect!
  expect(inertia).to have_flash(notice: 'User created!')
end

it 'returns validation errors on failure' do
  post users_path, params: { user: { name: '' } }

  follow_redirect!
  expect(inertia).to have_props(errors: hash_including('name' => anything))
end

Test Shared Props

Shared props from inertiashare are included in inertia.props. The inertia helper is available in type: :request specs after requiring inertiarails/rspec:

it 'includes shared auth data' do
  sign_in(user)
  get dashboard_path

  expect(inertia).to have_props(
    auth: hash_including(user: hash_including(id: user.id))
  )
end
it 'excludes auth data for unauthenticated users' do
  get dashboard_path

  expect(inertia).to have_props(auth: hash_including(user: nil))
end

Test Deferred Props

it 'defers expensive analytics data' do
  get dashboard_path

  expect(inertia).to have_deferred_props(:analytics, :statistics)
  expect(inertia).to have_deferred_props(:slow_data, group: :slow)
end

Partial Reload Helpers

it 'supports partial reload' do
  get users_path

  # Simulate partial reload — only fetch specific props
  inertia_reload_only(:users, :pagination)

  # Or exclude specific props
  inertia_reload_except(:expensive_stats)

  # Load deferred props
  inertia_load_deferred_props(:default)
  inertia_load_deferred_props # loads all groups
end

Test External Redirects (inertia_location)

it 'redirects to Stripe via inertia_location' do
  post checkout_path

  # inertia_location returns 409 with X-Inertia-Location header
  expect(response).to have_http_status(:conflict)
  expect(response.headers['X-Inertia-Location']).to match(/stripe\.com/)
end

NEVER Test These

  • Inertia framework behavior — don't test that <Form> sends CSRF tokens or that router.visit works. Test YOUR controller logic.
  • Exact prop structure — use have_props(users: satisfy { ... }), not deep equality on full JSON. Brittle tests break when you add a column.
  • Flash without followredirect! — after POST/PATCH/DELETE with redirect, you MUST followredirect! before asserting flash or props. Without it you're asserting against the 302, not the page.
  • Deferred prop values on initial load — deferred props are nil in the initial response because they're fetched in a separate request after page render. Use havedeferredprops(:key) to verify they're registered, or inertialoaddeferred_props to resolve them in tests.
  • Mocked Inertia responses — use type: :request specs that exercise the full stack. type: :controller specs with assigns don't work because Inertia uses a custom render pipeline that only executes in the full request cycle.

Direct Access (use matchers above when possible)

inertia.component       # => 'users/index'
inertia.props           # => { users: [...] }
inertia.props[:users]   # direct prop access
inertia.flash           # => { notice: 'Created!' }
inertia.deferred_props  # => { default: [:analytics], slow: [:report] }

Related Skills

  • Controller patternsinertia-rails-controllers (prop types, flash, PRG)
  • Form flowsinertia-rails-forms (submission, validation)
  • Deferred/shared propsinertia-rails-pages (Deferred, usePage)

References

MANDATORY — READ ENTIRE FILE when writing Minitest tests (not RSpec): [references/minitest.md](references/minitest.md) (~40 lines) — Minitest assertions equivalent to the RSpec matchers above.

Do NOT load minitest.md for RSpec projects — the matchers above are all you need.