Skip to content

Commit 10a14fa

Browse files
committed
Creating a singleton per arguments passed to git_version
1 parent 2eeef52 commit 10a14fa

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

GitVersionExe/GemAssets/lib/git_version.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
module GitVersion
44
def git_version(args = nil)
5-
Parser.new(args)
5+
parsers.fetch(args) { |a| parsers[a] = Parser.new(a) }
6+
end
7+
8+
private
9+
def parsers
10+
@parsers ||= {}
611
end
712
end

GitVersionExe/GemAssets/spec/lib/git_version_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,30 @@
66
it 'should create a ' + GitVersion::Parser.to_s do
77
expect(git_version).to be_an_instance_of(GitVersion::Parser)
88
end
9+
10+
it 'should create a singleton ' + GitVersion::Parser.to_s do
11+
expect(git_version).to equal(git_version)
12+
end
13+
14+
describe 'passing arguments' do
15+
it 'should yield the same instance per argument' do
16+
expect(git_version('foo')).to equal(git_version('foo'))
17+
end
18+
19+
it 'should yield different instances for different arguments' do
20+
expect(git_version('foo')).not_to equal_no_diff(git_version('bar'))
21+
end
22+
23+
def equal_no_diff(expected)
24+
expected = equal(expected)
25+
26+
# Turn off diffing for this matcher as it calls GitVersion::Parser#to_ary which will fail because GitVersion.exe
27+
# cannot be found.
28+
def expected.diffable?
29+
false
30+
end
31+
32+
expected
33+
end
34+
end
935
end

0 commit comments

Comments
 (0)