Class: Glib::Test::ChangedFilesRubocop

Inherits:
ActiveSupport::TestCase
  • Object
show all
Defined in:
lib/glib/test/changed_files_rubocop.rb

Overview

Fast RuboCop guard for the subset-run workflow.

Lives in glib-web's test helper so any project that includes Glib::TestHelpers into ActiveSupport::TestCase picks it up. Minitest runs all loaded test classes on every invocation, so this fires on every rails test — but it lints ONLY the files you have changed in the working tree (unstaged + staged + untracked). That keeps it fast and fails the run the moment an edited file has an offense.

Skip with SKIP_CHANGED_RUBOCOP=1 during tight debug loops. Auto-skips on CI because gem caches put thousands of vendored .rb files into the working tree (the "working-tree diff == your edits" premise breaks).

Constant Summary collapse

RUBOCOP_EXTENSIONS =

Extensions RuboCop targets by default (see its AllCops/Include). We rely on --force-exclusion to honour the project's AllCops/Exclude.

%w[.rb .rake .jbuilder .gemspec].freeze

Instance Method Summary collapse

Instance Method Details

#test_changed_files_are_rubocop_cleanObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/glib/test/changed_files_rubocop.rb', line 25

def test_changed_files_are_rubocop_clean
  skip 'opted out via SKIP_CHANGED_RUBOCOP' if ENV['SKIP_CHANGED_RUBOCOP'] == '1'
  skip 'CI lints every file separately; this guard is for local working-tree edits' if ENV['CI']

  files = changed_ruby_files
  # IMPORTANT: never call rubocop with zero paths — it would lint the whole repo.
  skip 'no changed Ruby files in the working tree' if files.empty?

  output = `bundle exec rubocop --force-exclusion --format simple #{files.shelljoin} 2>&1`

  assert(
    $CHILD_STATUS.success?,
    'RuboCop offenses in files you changed (fix them with `rubocop -a`):' \
    "\n\n#{output}"
  )
end