summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-10-12 14:12:07 +0200
committerJacob Vosmaer <jacob@gitlab.com>2017-10-12 14:12:07 +0200
commit0d62129e1f12d866b2a4dd49433f166a61e921a1 (patch)
tree81a3e70494f2514ca1fc0163ca14fc01c847220f
parente892ffdd027ea1f66757c71c5c5e086fc213717e (diff)
downloadgitlab-ce-0d62129e1f12d866b2a4dd49433f166a61e921a1.tar.gz
Use a table-driven test
-rw-r--r--spec/lib/gitlab/git/env_spec.rb41
1 files changed, 24 insertions, 17 deletions
diff --git a/spec/lib/gitlab/git/env_spec.rb b/spec/lib/gitlab/git/env_spec.rb
index bbd67a8b47a..24cb6de3009 100644
--- a/spec/lib/gitlab/git/env_spec.rb
+++ b/spec/lib/gitlab/git/env_spec.rb
@@ -54,25 +54,32 @@ describe Gitlab::Git::Env do
describe ".to_env_hash" do
context 'with RequestStore.store enabled' do
- before do
- allow(RequestStore).to receive(:active?).and_return(true)
-
- # These values are not 100% realistic but they exercise the possible
- # inputs while staying in the whitelist.
- described_class.set(
- GIT_OBJECT_DIRECTORY: nil,
- GIT_OBJECT_DIRECTORY_RELATIVE: ['foo'],
- GIT_ALTERNATE_OBJECT_DIRECTORIES: 'bar',
- GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: []
- )
+ using RSpec::Parameterized::TableSyntax
+
+ let(:key) { 'GIT_OBJECT_DIRECTORY' }
+ subject { described_class.to_env_hash }
+
+ where(:input, :output) do
+ nil | nil
+ 'foo' | 'foo'
+ [] | ''
+ ['foo'] | 'foo'
+ ['foo', 'bar'] | 'foo:bar'
end
- it 'returns an env hash' do
- expect(described_class.to_env_hash).to eq({
- 'GIT_OBJECT_DIRECTORY_RELATIVE' => 'foo',
- 'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar',
- 'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => ''
- })
+ with_them do
+ before do
+ allow(RequestStore).to receive(:active?).and_return(true)
+ described_class.set(key.to_sym => input)
+ end
+
+ it 'puts the right value in the hash' do
+ if output
+ expect(subject.fetch(key)).to eq(output)
+ else
+ expect(subject.has_key?(key)).to eq(false)
+ end
+ end
end
end
end