Commit 4aa6e6e3 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Just create the class from methods

parent 4cc6c539
...@@ -9,30 +9,26 @@ describe Gitlab::Utils::Override do ...@@ -9,30 +9,26 @@ describe Gitlab::Utils::Override do
end end
end end
shared_examples 'good derivation' do def good
subject do derived.module_eval do
derived.module_eval do override :good
override :good def good
def good super.succ
super.succ
end
end end
derived
end end
derived
end end
shared_examples 'bad derivation' do def bad
subject do derived.module_eval do
derived.module_eval do override :bad
override :bad def bad
def bad true
true
end
end end
derived
end end
derived
end end
describe '#override' do describe '#override' do
...@@ -41,36 +37,28 @@ describe Gitlab::Utils::Override do ...@@ -41,36 +37,28 @@ describe Gitlab::Utils::Override do
stub_env('STATIC_VERIFICATION', 'true') stub_env('STATIC_VERIFICATION', 'true')
end end
it_behaves_like 'good derivation' do it 'checks ok for overriding method' do
it 'checks ok for overriding method' do result = good.new(0).good
result = subject.new(0).good
expect(result).to eq(1) expect(result).to eq(1)
end
end end
it_behaves_like 'bad derivation' do it 'raises NotImplementedError when it is not overriding anything' do
it 'raises NotImplementedError when it is not overriding anything' do expect { bad }.to raise_error(NotImplementedError)
expect { subject }.to raise_error(NotImplementedError)
end
end end
end end
context 'when STATIC_VERIFICATION is not set' do context 'when STATIC_VERIFICATION is not set' do
it_behaves_like 'good derivation' do it 'does not complain when it is overriding anything' do
it 'does not complain when it is overriding anything' do result = good.new(0).good
result = subject.new(0).good
expect(result).to eq(1) expect(result).to eq(1)
end
end end
it_behaves_like 'bad derivation' do it 'does not complain when it is not overriding anything' do
it 'does not complain when it is not overriding anything' do result = bad.new(0).bad
result = subject.new(0).bad
expect(result).to eq(true) expect(result).to eq(true)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment