Sha256: 7932e574b512bb6fb414b90fe344829c6caae7ca8e2183b24709f5459bb59a15

Contents?: true

Size: 1.25 KB

Versions: 22

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # 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.
    class Generator
      TEST_TEMPLATE = <<~TEST
        # frozen_string_literal: true

        require '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

      def write_test
        write_unless_file_exists(test_path, generated_test)
      end

      private

      def test_path
        File.join(
          'test',
          'rubocop',
          'cop',
          'minitest',
          "#{snake_case(badge.cop_name.to_s)}_test.rb"
        )
      end

      def generated_test
        generate(TEST_TEMPLATE)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rubocop-minitest-0.20.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.20.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.19.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.19.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.18.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.17.2 lib/rubocop/cop/generator.rb
rubocop-minitest-0.17.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.17.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.16.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.15.2 lib/rubocop/cop/generator.rb
rubocop-minitest-0.15.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.15.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.14.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.13.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.12.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.12.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.11.1 lib/rubocop/cop/generator.rb
rubocop-minitest-0.11.0 lib/rubocop/cop/generator.rb
rubocop-minitest-0.10.3 lib/rubocop/cop/generator.rb
rubocop-minitest-0.10.2 lib/rubocop/cop/generator.rb