debian-mirror-gitlab/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb

174 lines
4.6 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2019-02-15 15:39:39 +05:30
require_relative '../../../rubocop/cop/inject_enterprise_edition_module'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
2019-02-15 15:39:39 +05:30
subject(:cop) { described_class.new }
2021-06-08 01:23:25 +05:30
it 'flags the use of `prepend_mod_with` in the middle of a file' do
2019-02-15 15:39:39 +05:30
expect_offense(<<~SOURCE)
class Foo
2021-06-08 01:23:25 +05:30
prepend_mod_with('Foo')
^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
2019-02-15 15:39:39 +05:30
end
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'flags the use of `include_mod_with` in the middle of a file' do
2019-12-04 20:38:33 +05:30
expect_offense(<<~SOURCE)
class Foo
2021-06-08 01:23:25 +05:30
include_mod_with('Foo')
^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
2019-12-04 20:38:33 +05:30
end
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'flags the use of `extend_mod_with` in the middle of a file' do
2019-03-02 22:35:43 +05:30
expect_offense(<<~SOURCE)
class Foo
2021-06-08 01:23:25 +05:30
extend_mod_with('Foo')
^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
2019-02-15 15:39:39 +05:30
end
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'does not flag the use of `prepend_mod_with` on the last line' do
2019-02-15 15:39:39 +05:30
expect_no_offenses(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.prepend_mod_with('Foo')
2019-02-15 15:39:39 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'does not flag the use of `include_mod_with` on the last line' do
2019-02-15 15:39:39 +05:30
expect_no_offenses(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.include_mod_with('Foo')
2019-02-15 15:39:39 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'does not flag the use of `extend_mod_with` on the last line' do
2019-02-15 15:39:39 +05:30
expect_no_offenses(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.extend_mod_with('Foo')
2019-02-15 15:39:39 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'does not flag the double use of `X_mod_with` on the last line' do
2020-05-24 23:13:21 +05:30
expect_no_offenses(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.extend_mod_with('Foo')
Foo.include_mod_with('Foo')
Foo.prepend_mod_with('Foo')
2020-05-24 23:13:21 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'does not flag the use of `prepend_mod_with` as long as all injections are at the end of the file' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.include_mod_with('Foo')
Foo.prepend_mod_with('Foo')
2020-06-23 00:09:42 +05:30
Foo.include(Bar)
# comment on prepending Bar
Foo.prepend(Bar)
SOURCE
end
2019-02-15 15:39:39 +05:30
it 'autocorrects offenses by just disabling the Cop' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~SOURCE)
class Foo
2021-06-08 01:23:25 +05:30
prepend_mod_with('Foo')
^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
include Bar
2021-03-11 19:13:27 +05:30
end
SOURCE
expect_correction(<<~SOURCE)
class Foo
2021-06-08 01:23:25 +05:30
prepend_mod_with('Foo') # rubocop: disable Cop/InjectEnterpriseEditionModule
include Bar
2021-03-11 19:13:27 +05:30
end
2019-10-12 21:52:04 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'disallows the use of prepend to inject an extension module' do
2019-10-12 21:52:04 +05:30
expect_offense(<<~SOURCE)
class Foo
end
Foo.prepend(EE::Foo)
2021-06-08 01:23:25 +05:30
^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
2019-10-12 21:52:04 +05:30
SOURCE
end
2019-12-04 20:38:33 +05:30
it 'disallows the use of prepend to inject a QA::EE module' do
expect_offense(<<~SOURCE)
class Foo
end
Foo.prepend(QA::EE::Foo)
2021-06-08 01:23:25 +05:30
^^^^^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
2019-12-04 20:38:33 +05:30
SOURCE
end
2019-10-12 21:52:04 +05:30
it 'disallows the use of extend to inject an EE module' do
expect_offense(<<~SOURCE)
class Foo
2019-02-15 15:39:39 +05:30
end
2019-10-12 21:52:04 +05:30
Foo.extend(EE::Foo)
2021-06-08 01:23:25 +05:30
^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
2019-10-12 21:52:04 +05:30
SOURCE
end
it 'disallows the use of include to inject an EE module' do
expect_offense(<<~SOURCE)
class Foo
end
Foo.include(EE::Foo)
2021-06-08 01:23:25 +05:30
^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
2019-10-12 21:52:04 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'disallows the use of prepend_mod_with without a String' do
2019-10-12 21:52:04 +05:30
expect_offense(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.prepend_mod_with(Foo)
^^^ extension modules to inject must be specified as a String
2019-10-12 21:52:04 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'disallows the use of include_mod_with without a String' do
2019-10-12 21:52:04 +05:30
expect_offense(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.include_mod_with(Foo)
^^^ extension modules to inject must be specified as a String
2019-10-12 21:52:04 +05:30
SOURCE
end
2021-06-08 01:23:25 +05:30
it 'disallows the use of extend_mod_with without a String' do
2019-10-12 21:52:04 +05:30
expect_offense(<<~SOURCE)
class Foo
end
2021-06-08 01:23:25 +05:30
Foo.extend_mod_with(Foo)
^^^ extension modules to inject must be specified as a String
2019-02-15 15:39:39 +05:30
SOURCE
end
end