Skip to content

Comments

feat(rspec): add RSpec test runner with compact output (Rails/Ruby)#198

Open
deril wants to merge 2 commits intortk-ai:masterfrom
deril:feat/rspec-support
Open

feat(rspec): add RSpec test runner with compact output (Rails/Ruby)#198
deril wants to merge 2 commits intortk-ai:masterfrom
deril:feat/rspec-support

Conversation

@deril
Copy link

@deril deril commented Feb 18, 2026

Summary

  • New command: rtk rspec — compact RSpec output for Rails/Ruby test suites
  • Token savings: 60-90% by parsing --format json output and showing only what matters
  • Hook rewrites: rspec, bin/rspec, bundle exec rspec, bundle exec rails specrtk rspec
  • mise.toml: pin Rust toolchain for contributors using mise

How it works

RSpec's --format json is injected automatically (unless the user already passes --format). The JSON is parsed and reduced to:

✓ RSpec: 42 passed (0.12s)

Or on failures:

RSpec: 38 passed, 2 failed, 3 pending (0.34s)
═══════════════════════════════════════

Failures:
1. ❌ User saves to database
   ./spec/models/user_spec.rb:10
   ExpectationNotMetError: expected true but got false
   ./spec/models/user_spec.rb:11:in `block'

2. ❌ Post sends notification
   ./spec/mailers/post_mailer_spec.rb:22
   ...

Key details:

  • Auto-detects bundle exec rspec when a Gemfile mentioning rspec is present
  • bin/rspec supported: Rails binstub pattern intercepted by hook
  • Gem backtrace stripped: lines from /gems/ and lib/rspec are skipped
  • Exception class shortened: RSpec::Expectations::ExpectationNotMetErrorExpectationNotMetError
  • Cap at 5 failures inline, ... +N more for the rest
  • Fallback: plain-text summary parser when JSON is unavailable

Test plan

  • 17 unit tests (all paths, token savings ≥60%, edge cases, fallback parser)
  • cargo fmt --all --check clean
  • cargo clippy --all-targets clean (0 new warnings)
  • Full test suite: 395/395 passing
  • Manual: tested on real Rails project (attensi-backend)
    $ rtk rspec spec/models/accountability_spec.rb
    ✓ RSpec: 1 passed (3.94s)
    
    $ rtk rspec spec/models/avatar_spec.rb
    ✓ RSpec: 6 passed (1.12s)
    

🤖 Generated with Claude Code

deril and others added 2 commits February 18, 2026 14:45
Adds `rtk rspec` command for Rails/Ruby test suites with 60-90% token savings.

- Parse RSpec's `--format json` output (injected automatically)
- Auto-detect `bundle exec rspec` when Gemfile contains "rspec"
- Compact success: `✓ RSpec: 42 passed (0.12s)`
- Failures show: test name, file:line, exception class + message, backtrace (gems stripped)
- Cap at 5 failures inline, `... +N more` for the rest
- Pending tests shown in count
- Fallback text parser when JSON unavailable
- 17 unit tests covering all paths and token savings assertions
- Hook rewrites: `rspec`, `bundle exec rspec`, `bundle exec rails spec` → `rtk rspec`
- Add mise.toml to pin Rust toolchain for mise users

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rails projects using binstubs invoke `bin/rspec` instead of bare `rspec`.
Add hook pattern so it gets rewritten to `rtk rspec` transparently.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

Thanks for the contribution! Could you rebase on master? The branch is 2 commits behind. We'll review once it's up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants