From 5becdf01941e3a471def26dd82282784c58b5590 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 9 Mar 2017 12:18:55 +0100 Subject: Implement GitLab QA release inflection strategy --- qa/spec/runtime/release_spec.rb | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 qa/spec/runtime/release_spec.rb (limited to 'qa/spec/runtime/release_spec.rb') diff --git a/qa/spec/runtime/release_spec.rb b/qa/spec/runtime/release_spec.rb new file mode 100644 index 00000000000..4995ad48ee6 --- /dev/null +++ b/qa/spec/runtime/release_spec.rb @@ -0,0 +1,62 @@ +describe QA::Runtime::Release do + context 'when release version has extension strategy' do + subject { described_class.new('CE') } + let(:strategy) { spy('CE::Strategy') } + + before do + stub_const('QA::CE::Strategy', strategy) + end + + describe '#has_strategy?' do + it 'return true' do + expect(subject.has_strategy?).to be true + end + end + + describe '#strategy' do + it 'return the strategy constant' do + expect(subject.strategy).to eq QA::CE::Strategy + end + end + + describe 'delegated class methods' do + it 'delegates all calls to strategy class' do + described_class.some_method(1, 2) + + expect(strategy).to have_received(:some_method) + .with(1, 2) + end + end + end + + context 'when release version does not have extension strategy' do + subject { described_class.new('CE') } + + describe '#has_strategy?' do + it 'returns false' do + expect(subject.has_strategy?).to be false + end + end + + describe '#strategy' do + it 'raises error' do + expect { subject.strategy }.to raise_error(NameError) + end + end + + describe 'delegated class methods' do + it 'behaves like a null object and does nothing' do + expect { described_class.some_method(2, 3) }.not_to raise_error + end + end + end + + context 'when release version is invalid or unspecified' do + describe '#new' do + it 'raises an exception' do + expect { described_class.new(nil) } + .to raise_error(described_class::UnspecifiedReleaseError) + end + end + end +end -- cgit v1.2.1 From 175a3dfda00fb5a2bf1703803277ee4abb721baf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 9 Mar 2017 15:04:05 +0100 Subject: Fix GitLab QA release inflector strategy --- qa/spec/runtime/release_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'qa/spec/runtime/release_spec.rb') diff --git a/qa/spec/runtime/release_spec.rb b/qa/spec/runtime/release_spec.rb index 4995ad48ee6..97f0b7e3c89 100644 --- a/qa/spec/runtime/release_spec.rb +++ b/qa/spec/runtime/release_spec.rb @@ -5,6 +5,7 @@ describe QA::Runtime::Release do before do stub_const('QA::CE::Strategy', strategy) + stub_const('QA::EE::Strategy', strategy) end describe '#has_strategy?' do @@ -32,6 +33,11 @@ describe QA::Runtime::Release do context 'when release version does not have extension strategy' do subject { described_class.new('CE') } + before do + hide_const('QA::CE::Strategy') + hide_const('QA::EE::Strategy') + end + describe '#has_strategy?' do it 'returns false' do expect(subject.has_strategy?).to be false -- cgit v1.2.1 From 0778cad285a7b8fac2487f2611a601b2e9326c5d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 13 Mar 2017 11:23:37 +0100 Subject: Do not use GITLAB_RELEASE env to define QA strategy [ci skip] --- qa/spec/runtime/release_spec.rb | 45 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'qa/spec/runtime/release_spec.rb') diff --git a/qa/spec/runtime/release_spec.rb b/qa/spec/runtime/release_spec.rb index 97f0b7e3c89..5d12315be5b 100644 --- a/qa/spec/runtime/release_spec.rb +++ b/qa/spec/runtime/release_spec.rb @@ -1,11 +1,10 @@ describe QA::Runtime::Release do context 'when release version has extension strategy' do - subject { described_class.new('CE') } - let(:strategy) { spy('CE::Strategy') } + subject { described_class.new('VER') } + let(:strategy) { spy('VER::Strategy') } before do - stub_const('QA::CE::Strategy', strategy) - stub_const('QA::EE::Strategy', strategy) + stub_const('QA::VER::Strategy', strategy) end describe '#has_strategy?' do @@ -16,11 +15,19 @@ describe QA::Runtime::Release do describe '#strategy' do it 'return the strategy constant' do - expect(subject.strategy).to eq QA::CE::Strategy + expect(subject.strategy).to eq QA::VER::Strategy end end describe 'delegated class methods' do + before do + allow_any_instance_of(described_class) + .to receive(:has_strategy?).and_return(true) + + allow_any_instance_of(described_class) + .to receive(:strategy).and_return(strategy) + end + it 'delegates all calls to strategy class' do described_class.some_method(1, 2) @@ -31,12 +38,7 @@ describe QA::Runtime::Release do end context 'when release version does not have extension strategy' do - subject { described_class.new('CE') } - - before do - hide_const('QA::CE::Strategy') - hide_const('QA::EE::Strategy') - end + subject { described_class.new('NOVER') } describe '#has_strategy?' do it 'returns false' do @@ -50,18 +52,23 @@ describe QA::Runtime::Release do end end - describe 'delegated class methods' do + describe 'does not delegate class methods' do + before do + allow_any_instance_of(described_class) + .to receive(:has_strategy?).and_return(false) + end + it 'behaves like a null object and does nothing' do expect { described_class.some_method(2, 3) }.not_to raise_error end - end - end - context 'when release version is invalid or unspecified' do - describe '#new' do - it 'raises an exception' do - expect { described_class.new(nil) } - .to raise_error(described_class::UnspecifiedReleaseError) + it 'returns nil' do + expect(described_class.something).to be_nil + end + + it 'does not delegate to strategy object' do + expect_any_instance_of(described_class) + .not_to receive(:strategy) end end end -- cgit v1.2.1 From 0731365b9de9411a937bd786d6e3fd7e10099800 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 13 Mar 2017 13:54:33 +0100 Subject: Add GitLab QA CE strategy and simplify inflector --- qa/spec/runtime/release_spec.rb | 53 +++++++++++------------------------------ 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'qa/spec/runtime/release_spec.rb') diff --git a/qa/spec/runtime/release_spec.rb b/qa/spec/runtime/release_spec.rb index 5d12315be5b..e6b5a8dc315 100644 --- a/qa/spec/runtime/release_spec.rb +++ b/qa/spec/runtime/release_spec.rb @@ -1,33 +1,25 @@ describe QA::Runtime::Release do context 'when release version has extension strategy' do - subject { described_class.new('VER') } - let(:strategy) { spy('VER::Strategy') } + let(:strategy) { spy('strategy') } before do - stub_const('QA::VER::Strategy', strategy) + stub_const('QA::CE::Strategy', strategy) + stub_const('QA::EE::Strategy', strategy) end - describe '#has_strategy?' do - it 'return true' do - expect(subject.has_strategy?).to be true + describe '#version' do + it 'return either CE or EE version' do + expect(subject.version).to eq(:CE).or eq(:EE) end end describe '#strategy' do it 'return the strategy constant' do - expect(subject.strategy).to eq QA::VER::Strategy + expect(subject.strategy).to eq strategy end end describe 'delegated class methods' do - before do - allow_any_instance_of(described_class) - .to receive(:has_strategy?).and_return(true) - - allow_any_instance_of(described_class) - .to receive(:strategy).and_return(strategy) - end - it 'delegates all calls to strategy class' do described_class.some_method(1, 2) @@ -38,37 +30,20 @@ describe QA::Runtime::Release do end context 'when release version does not have extension strategy' do - subject { described_class.new('NOVER') } - - describe '#has_strategy?' do - it 'returns false' do - expect(subject.has_strategy?).to be false - end + before do + allow_any_instance_of(described_class) + .to receive(:version).and_return('something') end describe '#strategy' do it 'raises error' do - expect { subject.strategy }.to raise_error(NameError) + expect { subject.strategy }.to raise_error(LoadError) end end - describe 'does not delegate class methods' do - before do - allow_any_instance_of(described_class) - .to receive(:has_strategy?).and_return(false) - end - - it 'behaves like a null object and does nothing' do - expect { described_class.some_method(2, 3) }.not_to raise_error - end - - it 'returns nil' do - expect(described_class.something).to be_nil - end - - it 'does not delegate to strategy object' do - expect_any_instance_of(described_class) - .not_to receive(:strategy) + describe 'delegated class methods' do + it 'raises error' do + expect { described_class.some_method(2, 3) }.to raise_error(LoadError) end end end -- cgit v1.2.1