Module: RuboCop::Cop::MinitestGenerator

Defined in:
lib/rubocop/cop/minitest_generator.rb

Overview

Source and test generator for new cops

This generator will take a cop name and generate a source file and test file when given a valid qualified cop name.

Constant Summary collapse

TEST_TEMPLATE =
<<~TEST
  # frozen_string_literal: true

  require_relative '../../../test_helper'

  class %<cop_name>sTest < Minitest::Test
    def test_registers_offense_when_using_bad_method
      assert_offense(<<~RUBY)
        bad_method
        ^^^^^^^^^^ Use `#good_method` instead of `#bad_method`.
      RUBY

      assert_correction(<<~RUBY)
        good_method
      RUBY
    end

    def test_does_not_register_offense_when_using_good_method
      assert_no_offenses(<<~RUBY)
        good_method
      RUBY
    end
  end
TEST

Instance Method Summary collapse

Instance Method Details

#write_testObject



37
38
39
# File 'lib/rubocop/cop/minitest_generator.rb', line 37

def write_test
  write_unless_file_exists(test_path, generated_test)
end