Skip to content

Incremental spec suite hygiene #169

Description

@eitoball

Summary

Incremental cleanup of the RSpec suite: reduce class pollution, extract shared helpers, and chip away at .rubocop_todo.yml exclusions — without rewriting the intentional inline-DSL spec style.

Problem

The spec suite documents DSL behavior well, but accumulates maintenance cost:

Issue Examples Impact
Constants defined inside describe blocks spec/comma/comma_spec.rb, AR/Mongoid specs RuboCop Lint/ConstantDefinitionInBlock excluded
Repeated class Foo names across examples Multiple files Order-dependent pollution if examples leak
Long inline expected CSV strings comma_spec.rb, users_controller_spec.rb Hard to read diffs
Stale RuboCop todo entries .rubocop_todo.yml Masks fixable offenses in touched files

The project intentionally uses inline classes to show DSL usage — this issue is about hygiene, not replacing that pattern entirely.

Proposed approach (incremental)

1. Shared helper for anonymous comma classes

# spec/support/comma_class_helper.rb
def define_comma_class(&block)
  Class.new do
    class_eval(&block)
  end
end

Use in new/changed specs; migrate old ones opportunistically.

2. CSV expectation helper

def expect_csv(output, headers:, rows:)
  expected = CSV.generate { |csv| csv << headers; rows.each { |r| csv << r } }
  expect(output).to eq(expected)
end

Reduces copy-paste in comma_spec and controller specs.

3. Shared fixture models (optional)

Move stable models like Book / Isbn patterns to spec/support/models/ only where duplication exceeds benefit — keep Book in spec/non_rails_app/ruby_classes.rb as the canonical example.

4. RuboCop todo reduction

When touching a spec file, fix or narrow exclusions instead of adding new ones.

Files likely involved

  • spec/support/ (new helpers)
  • spec/comma/comma_spec.rb
  • spec/comma/data_extractor_spec.rb
  • spec/comma/header_extractor_spec.rb
  • spec/controllers/users_controller_spec.rb
  • .rubocop_todo.yml

Acceptance criteria

  • At least one support helper added and used in 2+ spec files
  • No spec behavior changes (same examples, same expectations)
  • Document helper usage in a short comment at top of spec/support/comma_class_helper.rb
  • Reduce at least one entry from .rubocop_todo.yml OR file an explicit follow-up list of remaining exclusions
  • Not required: migrate every inline class in one PR

Labels (suggested)

refactor, tests, good first issue

Depends on

None. Best done alongside other refactor PRs (touch spec once).

Out of scope

  • Full spec rewrite
  • Changing Appraisal matrix or CI structure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions