2018-12-13 09:46:01 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 14:10:07 -04:00
|
|
|
require 'rubocop_spec_helper'
|
2018-12-13 09:46:01 -05:00
|
|
|
require_relative '../../../rubocop/cop/inject_enterprise_edition_module'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'flags the use of `prepend_mod_with` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2021-05-11 17:10:21 -04:00
|
|
|
prepend_mod_with('Foo')
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'flags the use of `include_mod_with` in the middle of a file' do
|
2019-08-28 11:20:06 -04:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2021-05-11 17:10:21 -04:00
|
|
|
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-08-28 11:20:06 -04:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
2022-08-16 17:12:07 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'flags the use of `extend_mod_with` in the middle of a file' do
|
2019-01-16 09:21:50 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2021-05-11 17:10:21 -04:00
|
|
|
extend_mod_with('Foo')
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'does not flag the use of `prepend_mod_with` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.prepend_mod_with('Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'does not flag the use of `include_mod_with` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.include_mod_with('Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'does not flag the use of `extend_mod_with` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.extend_mod_with('Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'does not flag the double use of `X_mod_with` on the last line' do
|
2020-05-12 11:10:33 -04:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.extend_mod_with('Foo')
|
|
|
|
Foo.include_mod_with('Foo')
|
|
|
|
Foo.prepend_mod_with('Foo')
|
2020-05-12 11:10:33 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'does not flag the use of `prepend_mod_with` as long as all injections are at the end of the file' do
|
2020-05-25 23:08:02 -04:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.include_mod_with('Foo')
|
|
|
|
Foo.prepend_mod_with('Foo')
|
2020-05-25 23:08:02 -04:00
|
|
|
|
|
|
|
Foo.include(Bar)
|
|
|
|
# comment on prepending Bar
|
|
|
|
Foo.prepend(Bar)
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2018-12-13 09:46:01 -05:00
|
|
|
it 'autocorrects offenses by just disabling the Cop' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2021-05-11 17:10:21 -04:00
|
|
|
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-01-26 13:09:30 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
|
|
|
|
expect_correction(<<~SOURCE)
|
|
|
|
class Foo
|
2021-05-11 17:10:21 -04:00
|
|
|
prepend_mod_with('Foo') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
include Bar
|
2021-01-26 13:09:30 -05:00
|
|
|
end
|
2019-07-26 08:52:18 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'disallows the use of prepend to inject an extension module' do
|
2019-07-26 08:52:18 -04:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.prepend(EE::Foo)
|
2021-05-11 17:10:21 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
|
2019-07-26 08:52:18 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-08-28 11:20:06 -04:00
|
|
|
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-05-11 17:10:21 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
|
2019-08-28 11:20:06 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'disallows the use of extend to inject an EE module' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
2019-07-26 08:52:18 -04:00
|
|
|
|
|
|
|
Foo.extend(EE::Foo)
|
2021-05-11 17:10:21 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
|
2019-07-26 08:52:18 -04:00
|
|
|
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-05-11 17:10:21 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
|
2019-07-26 08:52:18 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'disallows the use of prepend_mod_with without a String' do
|
2019-07-26 08:52:18 -04:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.prepend_mod_with(Foo)
|
|
|
|
^^^ extension modules to inject must be specified as a String
|
2019-07-26 08:52:18 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'disallows the use of include_mod_with without a String' do
|
2019-07-26 08:52:18 -04:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.include_mod_with(Foo)
|
|
|
|
^^^ extension modules to inject must be specified as a String
|
2019-07-26 08:52:18 -04:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
it 'disallows the use of extend_mod_with without a String' do
|
2019-07-26 08:52:18 -04:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Foo.extend_mod_with(Foo)
|
|
|
|
^^^ extension modules to inject must be specified as a String
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|