Skip to content

Incremental spec suite hygiene - #180

Merged
eitoball merged 2 commits into
masterfrom
eitoball/incremental-spec-suite-hygiene
Sep 6, 2026
Merged

Incremental spec suite hygiene#180
eitoball merged 2 commits into
masterfrom
eitoball/incremental-spec-suite-hygiene

Conversation

@eitoball

@eitoball eitoball commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What

Adds two RSpec support helpers and uses them to remove inline class-constant pollution and hand-rolled CSV strings from the spec suite (#169).

Why

The spec suite documents DSL behavior well but accumulates maintenance cost: describe/before blocks define real global constants (class Foo, class MySuperClass, ...), which pollutes the namespace and forces a Lint/ConstantDefinitionInBlock RuboCop exclusion, and several specs hand-roll long expected CSV strings that are easy to typo and hard to diff.

Changes

  • Add spec/support/comma_class_helper.rbdefine_comma_class(base = Object, &block) builds an anonymous class (optionally subclassing a given base, e.g. a Struct) instead of defining a named constant.
  • Add spec/support/csv_expectation_helper.rbexpect_csv(output, headers:, rows:, **csv_options) builds the expected string via CSV.generate and asserts equality, instead of hand-writing comma/quote-escaped strings.
  • Migrate spec/comma/comma_spec.rb: replace all inline class Foo/Bar/MySuperClass/ChildClassComma/ChildClassNoComma/ReopenedSuperClass/ReopenedChildNoComma constants (including the STI and class-reopening tests) with define_comma_class, and replace the hand-rolled CSV expectation strings with expect_csv. Same examples, same expectations — only how the class/expected-string is built changes.
  • Apply define_comma_class in spec/comma/data_extractor_spec.rb and spec/comma/header_extractor_spec.rb, replacing the existing Class.new(Struct.new(...)) pattern.
  • Apply expect_csv in spec/controllers/users_controller_spec.rb for the CSV-comparison cases the helper cleanly covers (default, style, header-toggle-on, force_quotes); left the BOM, header-toggle-off, and combined col_sep/row_sep cases as plain heredocs since they don't fit the helper's shape.
  • .rubocop_todo.yml: drop spec/comma/comma_spec.rb from the Lint/ConstantDefinitionInBlock exclude list now that it defines no class constants (verified via a fresh --auto-gen-config run — the remaining 3 files there are Rails/Mongoid/DataMapper model specs, out of scope).

Verified locally: full non-Rails RSpec suite (57 examples) passes, bundle exec rubocop (37 files) is clean. spec/controllers/users_controller_spec.rb only runs under if defined?(Rails); a local Rails gemfile couldn't be built in this sandbox (unrelated nokogiri native-build issue), so those specific changes were verified by hand/ruby -c and rely on CI's Appraisal matrix for execution.

Copilot AI lite review requested due to automatic review settings September 5, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are test/support-only refactors that appear behavior-preserving and the helper loading mechanism is already in place via spec/spec_helper.rb.

Pull request overview

This PR incrementally improves RSpec suite hygiene by introducing small support helpers that avoid global class-constant pollution and reduce brittle hand-written CSV expectation strings, while keeping the existing example structure and intent intact.

Changes:

  • Added define_comma_class helper to build anonymous classes (optionally subclassing a provided base) for specs.
  • Added expect_csv helper to generate expected CSV via CSV.generate from headers/rows and compare to actual output.
  • Migrated several specs to use these helpers and narrowed .rubocop_todo.yml by removing the Lint/ConstantDefinitionInBlock exclusion for spec/comma/comma_spec.rb.
File summaries
File Description
spec/support/comma_class_helper.rb Adds define_comma_class to avoid defining global constants in examples.
spec/support/csv_expectation_helper.rb Adds expect_csv to generate expected CSV strings consistently via CSV.generate.
spec/controllers/users_controller_spec.rb Replaces several heredoc CSV expectations with expect_csv where the shape matches.
spec/comma/comma_spec.rb Migrates inline class constants and hand-rolled CSV strings to the new helpers.
spec/comma/data_extractor_spec.rb Uses define_comma_class instead of ad-hoc Class.new(Struct...) definitions.
spec/comma/header_extractor_spec.rb Uses define_comma_class instead of ad-hoc Class.new(Struct...) definitions.
.rubocop_todo.yml Removes the Lint/ConstantDefinitionInBlock exclusion for spec/comma/comma_spec.rb.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

eitoball and others added 2 commits September 5, 2026 21:12
Reduces spec pollution and copy-paste per #169: introduces
define_comma_class and expect_csv, migrates comma_spec.rb's inline
class constants and hand-rolled CSV strings to use them, and applies
the same helpers in data_extractor_spec.rb, header_extractor_spec.rb,
and users_controller_spec.rb. Drops comma_spec.rb from the
Lint/ConstantDefinitionInBlock exclude list now that it defines no
class constants.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Class.new(base, &block) already handles a nil block gracefully, so
drop the redundant class_eval wrapper that raised ArgumentError when
called without one. Also convert the remaining Class.new(Struct.new)
call sites in comma_spec.rb and the last straightforward CSV heredoc
in users_controller_spec.rb to the new helpers for consistency.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 5, 2026 12:12
@eitoball
eitoball force-pushed the eitoball/incremental-spec-suite-hygiene branch from 61000e5 to 7f08010 Compare September 5, 2026 12:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are test-only refactors that preserve behavior while improving spec hygiene and reducing RuboCop todo scope.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@eitoball
eitoball merged commit 0be9189 into master Sep 6, 2026
73 checks passed
@eitoball
eitoball deleted the eitoball/incremental-spec-suite-hygiene branch September 6, 2026 00:03
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.

2 participants