diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2018-12-01 22:52:43 +0100 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2018-12-22 14:10:43 +0100 |
commit | d2851f41ba38a8292cd063aeb374f64541765bb9 (patch) | |
tree | 550c1fa4f2047789561a0bbee4c2938a8de505ca /spec | |
parent | 8f3cef87e77291d92401dd88b9db23e8879ed053 (diff) | |
download | gitlab-ce-d2851f41ba38a8292cd063aeb374f64541765bb9.tar.gz |
Extend override check to also check arity42125-extend-override-check-to-also-check-arity
Override now cares about parents method arity: if parents arity
doesn't match raises an error.
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 |