diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2018-08-25 00:08:34 +0200 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2018-08-29 16:56:34 +0200 |
commit | 2f0327b7d8ac46fcb30d957d54fab32b27f8625f (patch) | |
tree | 206bcb41c8a437a2245a14fa2ca1c5f3d17323d8 /spec/rubocop | |
parent | dad73a77843cb89e8e6d0069fe9a1956e6b304d6 (diff) | |
download | gitlab-ce-2f0327b7d8ac46fcb30d957d54fab32b27f8625f.tar.gz |
Adds Rubocop rule to enforce class_methods over module ClassMethods
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/prefer_class_methods_over_module_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb b/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb new file mode 100644 index 00000000000..64b1f1b948d --- /dev/null +++ b/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/prefer_class_methods_over_module' + +describe RuboCop::Cop::PreferClassMethodsOverModule do + include CopHelper + + subject(:cop) { described_class.new } + + it 'flags violation when using ClassMethods' do + expect_offense(<<~RUBY) + module Foo + module ClassMethods + ^^^^^^^^^^^^^^^^^^^ Do not use module ClassMethods, use class_methods block instead. + def a_class_method + end + end + end + RUBY + end + + it "doesn't flag violation when using class_methods" do + expect_no_offenses(<<~RUBY) + module Foo + class_methods do + def a_class_method + end + end + end + RUBY + end + + it "doesn't flag violation when not using either class_methods or ClassMethods" do + expect_no_offenses(<<~RUBY) + module Foo + def a_method + end + end + RUBY + end + + it 'autocorrects ClassMethods into class_methods' do + source = <<~RUBY + module Foo + module ClassMethods + def a_class_method + end + end + end + RUBY + autocorrected = autocorrect_source(source) + + expected_source = <<~RUBY + module Foo + class_methods do + def a_class_method + end + end + end + RUBY + expect(autocorrected).to eql(expected_source) + end +end |