diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-12-26 12:58:08 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-12-26 12:58:08 +0300 |
commit | 145079b3540ca832e1d981bbc685cc8c27d47ea0 (patch) | |
tree | 099cda679151facf2af4bd55cd64f5ca3f102736 /spec | |
parent | d0884ab6cd53e2b53339e1fe00a1919eba4a2807 (diff) | |
parent | d2851f41ba38a8292cd063aeb374f64541765bb9 (diff) |
Merge branch '42125-extend-override-check-to-also-check-arity' into 'master'
Resolve "Extend `override` check to also check arity"
Closes #42125
See merge request gitlab-org/gitlab-ce!23498
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/utils/override_spec.rb | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/spec/lib/gitlab/utils/override_spec.rb b/spec/lib/gitlab/utils/override_spec.rb index fc08ebcfc6d..9e7c97f8095 100644 --- a/spec/lib/gitlab/utils/override_spec.rb +++ b/spec/lib/gitlab/utils/override_spec.rb @@ -25,11 +25,21 @@ describe Gitlab::Utils::Override do let(:klass) { subject } - def good(mod) + def good(mod, bad_arity: false, negative_arity: false) mod.module_eval do override :good - def good - super.succ + + if bad_arity + def good(num) + end + elsif negative_arity + def good(*args) + super.succ + end + else + def good + super.succ + end end end @@ -56,6 +66,14 @@ describe Gitlab::Utils::Override do described_class.verify! end + it 'checks ok for overriding method using negative arity' do + good(subject, negative_arity: true) + result = instance.good + + expect(result).to eq(1) + described_class.verify! + end + it 'raises NotImplementedError when it is not overriding anything' do expect do bad(subject) @@ -63,6 +81,14 @@ describe Gitlab::Utils::Override do described_class.verify! end.to raise_error(NotImplementedError) end + + it 'raises NotImplementedError when overriding a method with different arity' do + expect do + good(subject, bad_arity: true) + instance.good(1) + described_class.verify! + end.to raise_error(NotImplementedError) + end end shared_examples 'checking as intended, nothing was overridden' do |