Skip to content

feat(core): broaden .understandignore starter — Ruby RSpec/Minitest patterns#597

Merged
Lum1104 merged 4 commits into
Egonex-AI:mainfrom
thejesh23:feat/understandignore-ruby-test-patterns
Jul 21, 2026
Merged

feat(core): broaden .understandignore starter — Ruby RSpec/Minitest patterns#597
Lum1104 merged 4 commits into
Egonex-AI:mainfrom
thejesh23:feat/understandignore-ruby-test-patterns

Conversation

@thejesh23

@thejesh23 thejesh23 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • EXACT_DIR_NAMES += spec — RSpec's canonical home directory (used by discourse, homebrew, gitlab, fastlane, rubocop, and every rspec-rails scaffold). This is the load-bearing addition: spec/ alone drives 46 pp of the 51% weighted total reduction below.
  • New TEST_PATTERN_GROUPS entry Ruby with 6 patterns (RSpec *_spec.rb, Minitest *_test.rb / test_*.rb, harness bootstraps spec_helper.rb / test_helper.rb / rails_helper.rb).
  • +3 tests in ignore-generator.test.ts; ordering invariant extended to place Ruby after Rust.
  • build + lint clean; ignore-generator suite 48/48 pass, core suite 898 pass (2 pre-existing wasm module resolution failures on scala-extractor.test.ts / swift-extractor.test.ts reproduce unmodified on origin/main).

SKILL.md unchanged — Phase 0.5 delegates to generate-ignore.mjs since a0155c5, so no inline duplicate to keep in sync.

Why these patterns (and not others)

Ruby is closer to C++ in ecosystem shape than to Rust: aggressive test clustering under known dirs, plus a few naming conventions the starter had never been taught about. The spec/ gap was the load-bearing miss — with it added, every RSpec-based project (which is most modern Rails-adjacent Ruby) sees the discourse-scale reduction the moment it opts in.

Rejected as too project-specific or ambiguous: **/*_shared_examples.rb (RSpec-only, files usually live under spec/support/ which is already caught by spec/), **/factories.rb (FactoryBot — under spec/factories/, same), **/schema.rb (Rails-generated, but path is db/schema.rb — surfaces via .gitignore extraction rather than a starter suggestion).

Kept spec_helper.rb / test_helper.rb / rails_helper.rb as separate opt-in globs because engines and multi-app monorepos occasionally reference them via require_relative from outside the canonical spec/test trees.

Token impact (measured across 10 public Ruby repos)

Methodology: gh api .../git/trees?recursive=1, Ruby source = .rb .rake .gemspec, 1 MiB ≈ 262K tokens. Two hero projects reported below — the highest percentage win and the highest absolute win — same pattern as PR #582.

Project Before (analyzed) After (analyzed) Reduction
rubocop/rubocop 10.38 MB / ~2.59M tok 3.38 MB / ~0.84M tok −1.75M (67%)
discourse/discourse 36.84 MB / ~9.21M tok 14.71 MB / ~3.67M tok −5.53M (60%)
  • rubocop — highest %. RSpec-dominant repo where spec/ was the bulk of the untouched source tree.
  • discourse — highest absolute saving. 3798 files under spec/ — the single largest un-caught test tree in the survey.

Weighted total across all 10 repos: −11.80M tok / 51% on 92 MB of Ruby source — the highest of any language group added so far. Full breakdown (for context, not repeated in the hero table): ruby/ruby 59% / −3.66M, rspec/rspec-rails 61%, fastlane/fastlane 42%, rails/rails 2% (already covered by existing test/ dir rule), Homebrew/brew 1%, jekyll/jekyll 0%, shopify/liquid 3%, basecamp/kamal 0%.

The spec/ dir rule alone accounts for 46 pp of the 51% weighted total; the file globs add another 5 pp by catching *_spec.rb in gem lib/ trees, Minitest files that leak outside test/ in Rails engines, and the helper bootstraps.

Test plan

  • pnpm --filter @understand-anything/core build — clean
  • pnpm --filter @understand-anything/core exec vitest run src/__tests__/ignore-generator.test.ts — 48/48 pass (3 new Ruby tests + the spec/ dir test)
  • pnpm --filter @understand-anything/core test — 898 pass, 2 pre-existing wasm-module failures also present on origin/main (unrelated: scala-extractor, swift-extractor)
  • pnpm lint — clean
  • Manual preview of generated .understandignore on a fixture with spec/, test/, plus a lib/foo.rb + lib/foo_spec.rb — Ruby group emitted after Rust, all six patterns present, # spec/ in the detected-dirs section, all commented

Closes #596

Ruby's second-most-common testing tool (arguably first in Rails-adjacent
projects — discourse, gitlab, homebrew all use RSpec) organises tests
under a top-level `spec/` directory rather than `test/`. The existing
list caught Minitest / Rails default `test/` but silently ingested
every `spec/**/*.rb` file for RSpec-based projects.

Add `spec` as a case-insensitive exact-name match. Kept separate from
the Ruby file-pattern group added in follow-up commits so users on
Minitest-only projects (rails/rails core, ruby/ruby) aren't affected.
Ruby ecosystems split between two test frameworks with different
file-naming conventions:

  RSpec       — `*_spec.rb`, canonically under `spec/`
                (discourse, homebrew, gitlab, fastlane, rubocop)
  Minitest    — `*_test.rb` / `test_*.rb`, canonically under `test/`
                (rails/rails, activerecord, ruby/ruby)

Both top-level dirs are now caught by EXACT_DIR_NAMES (`spec` was
added in the previous commit), but individual files sometimes leak
elsewhere — engine test files under `app/**/*_test.rb` in Rails
engines, gem repos that colocate small `*_spec.rb` beside
`lib/**/*.rb`. The file globs are what catch that shape.

Tests: assert Ruby sub-header and all three globs; extend the
stable-order invariant to place Ruby after Rust.
Test harness bootstrap files loaded by every test in the suite:

  spec_helper.rb   — RSpec baseline configuration
  test_helper.rb   — Minitest baseline configuration
  rails_helper.rb  — Rails-specific RSpec bootstrap (require rails
                     env + all initialisers)

These sit under `spec/` or `test/` in canonical layouts (already
caught by dir rules), but Rails engines and multi-app monorepos
sometimes reference them via `require_relative` from other paths.
Kept as separate opt-in globs so projects that share helpers with
production code paths (rare, but legal) can leave them commented.
The initial comment was speculative ("individual files sometimes leak
elsewhere"). Measurement across 10 major Ruby repos showed the picture
is much stronger and closer to C++ than to Rust:

  Weighted total reduction across the sample: 51% (−11.80M tokens on
  92 MB of Ruby source), the highest of any language group so far.
  spec/ dir rule alone drives 46 pp; file globs add the remaining 5 pp
  by catching *_spec.rb in gem lib/ trees, Minitest files leaking
  outside test/ in Rails engines, and helper bootstraps referenced
  via require_relative.

  Hero projects:
    rubocop/rubocop        67% (−1.75M tok)  highest percent
    discourse/discourse    60% (−5.53M tok)  highest absolute
    ruby/ruby              59% (−3.66M tok)
    rspec/rspec-rails      61% (−0.07M tok)
    fastlane/fastlane      42% (−0.73M tok)

Update the block comment so a future reader lands on the right mental
model — Ruby is a big win precisely because the ecosystem clusters
tests but under a directory (`spec/`) that the starter had previously
missed entirely.
@Lum1104
Lum1104 merged commit 6ae7187 into Egonex-AI:main Jul 21, 2026
2 checks passed
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.

feat(core): broaden .understandignore starter — Ruby RSpec/Minitest patterns

2 participants