summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2019-01-16 15:21:50 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2019-01-16 16:48:18 +0100
commit9722158c15300dd4507cbb49b4230ab36b36ae65 (patch)
tree234b63916e51894916d59aea2c13c967c65a9b27 /spec/rubocop
parent454942da67911ed6968b799f23c6b9080da7b856 (diff)
downloadgitlab-ce-9722158c15300dd4507cbb49b4230ab36b36ae65.tar.gz
Fix detecting nested EE constants in RuboCop
The InjectEnterpriseEditionModule cop would not detect certain nested EE constants such as `EE::Foo::Bar::Baz`. This could result in it not enforcing `prepend` being placed on the last line. This commit fixes this by just performing a string match on the line, instead of relying on AST matching.
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/inject_enterprise_edition_module_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
index 08ffc3c3a53..0ff777388e5 100644
--- a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
+++ b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
@@ -19,6 +19,41 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE
end
+ it 'does not flag the use of `prepend EEFoo` in the middle of a file' do
+ expect_no_offenses(<<~SOURCE)
+ class Foo
+ prepend EEFoo
+ end
+ SOURCE
+ end
+
+ it 'flags the use of `prepend EE::Foo::Bar` in the middle of a file' do
+ expect_offense(<<~SOURCE)
+ class Foo
+ prepend EE::Foo::Bar
+ ^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
+ end
+ SOURCE
+ end
+
+ it 'flags the use of `prepend(EE::Foo::Bar)` in the middle of a file' do
+ expect_offense(<<~SOURCE)
+ class Foo
+ prepend(EE::Foo::Bar)
+ ^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
+ end
+ SOURCE
+ end
+
+ it 'flags the use of `prepend EE::Foo::Bar::Baz` in the middle of a file' do
+ expect_offense(<<~SOURCE)
+ class Foo
+ prepend EE::Foo::Bar::Baz
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
+ end
+ SOURCE
+ end
+
it 'flags the use of `prepend ::EE` in the middle of a file' do
expect_offense(<<~SOURCE)
class Foo