File tree Expand file tree Collapse file tree 2 files changed +51
-7
lines changed Expand file tree Collapse file tree 2 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -23,22 +23,47 @@ def json
23
23
end
24
24
25
25
def gitversion_exe
26
- @gitversion_exe ||= File . join ( File . dirname ( __FILE__ ) , '../bin/GitVersion.exe' )
26
+ @gitversion_exe ||= File . expand_path ( File . join ( File . dirname ( __FILE__ ) , '../bin/GitVersion.exe' ) )
27
+ end
28
+
29
+ def inspect
30
+ unless @json
31
+
32
+ return <<EOF
33
+ #{ to_s }
34
+ Will invoke #{ cmd_string } when first used.
35
+ EOF
36
+
37
+ else
38
+
39
+ return <<EOF
40
+ #{ to_s }
41
+ Invoked #{ cmd_string } and parsed its output:
42
+ #{ json . inspect }
43
+ EOF
44
+
45
+ end
27
46
end
28
47
29
48
private
30
49
def run_gitversion
31
- cmd = [ gitversion_exe ]
32
- cmd << args
33
- cmd = cmd . flatten . reject ( &:nil? )
34
-
35
50
stdout_and_stderr , status = Open3 . capture2e ( *cmd )
36
51
37
- raise StandardError . new ( "Failed running #{ cmd . join ( ' ' ) } , #{ status } . We received the following output:\n #{ stdout_and_stderr } " ) unless status . success?
52
+ raise StandardError . new ( "Failed running #{ cmd_string } , #{ status } . We received the following output:\n #{ stdout_and_stderr } " ) unless status . success?
38
53
39
54
JSON . parse ( stdout_and_stderr )
40
55
end
41
56
57
+ def cmd
58
+ cmd = [ gitversion_exe ]
59
+ cmd << args
60
+ cmd . flatten . reject ( &:nil? )
61
+ end
62
+
63
+ def cmd_string
64
+ cmd . join ( ' ' )
65
+ end
66
+
42
67
def pascal_case ( str )
43
68
str
44
69
. to_s
Original file line number Diff line number Diff line change 2
2
3
3
describe GitVersion do
4
4
describe 'defaults' do
5
- its ( :gitversion_exe ) { should match ( %r|\. \. /bin/GitVersion.exe$| ) }
5
+ its ( :gitversion_exe ) { should match ( %r|/bin/GitVersion.exe$| ) }
6
6
its ( :args ) { should be_empty }
7
7
end
8
8
80
80
end
81
81
end
82
82
end
83
+
84
+ describe '#inspect' do
85
+ context 'no properties accessed yet' do
86
+ it 'writes what will happen' do
87
+ expect ( subject . inspect ) . to match ( /.+GitVersion.+\n Will invoke .+GitVersion.exe when first used./ )
88
+ end
89
+ end
90
+
91
+ context 'properties accessed' do
92
+ before {
93
+ allow ( Open3 ) . to receive ( :capture2e ) . and_return ( [ '{ "Sha": 1234 }' , OpenStruct . new ( success? : true ) ] )
94
+ }
95
+
96
+ it 'writes what happened' do
97
+ subject . sha
98
+ expect ( subject . inspect ) . to match ( /.+GitVersion.+\n Invoked .+GitVersion.exe and parsed its output:\n .+/ )
99
+ end
100
+ end
101
+ end
83
102
end
You can’t perform that action at this time.
0 commit comments