99
1010func TestRuby (t * testing.T ) {
1111 cases := []struct {
12+ Case string
1213 ExpectedString string
1314 ExpectedEnabled bool
1415 HasRbenv bool
@@ -22,13 +23,14 @@ func TestRuby(t *testing.T) {
2223 HasGemFile bool
2324 DisplayVersion bool
2425 }{
25- {ExpectedString : "" , ExpectedEnabled : false },
26- {ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasRubyFiles : true },
27- {ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasRakeFile : true },
28- {ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasGemFile : true },
29- {ExpectedString : "" , ExpectedEnabled : false , DisplayVersion : true , HasGemFile : true },
30- {ExpectedString : "" , ExpectedEnabled : false , DisplayVersion : true },
26+ {Case : "No files" , ExpectedString : "" , ExpectedEnabled : false },
27+ {Case : "Ruby files" , ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasRubyFiles : true },
28+ {Case : "Rakefile" , ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasRakeFile : true },
29+ {Case : "Gemfile" , ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : false , HasGemFile : true },
30+ {Case : "Gemfile with version" , ExpectedString : "" , ExpectedEnabled : true , DisplayVersion : true , HasGemFile : true },
31+ {Case : "No files with version" , ExpectedString : "" , ExpectedEnabled : false , DisplayVersion : true },
3132 {
33+ Case : "Version with chruby" ,
3234 ExpectedString : "ruby-2.6.3" ,
3335 ExpectedEnabled : true ,
3436 DisplayVersion : true ,
@@ -40,6 +42,7 @@ func TestRuby(t *testing.T) {
4042 rubinius-2.0.0-rc1` ,
4143 },
4244 {
45+ Case : "Version with chruby line 2" ,
4346 ExpectedString : "ruby-1.9.3-p392" ,
4447 ExpectedEnabled : true ,
4548 DisplayVersion : true ,
@@ -51,6 +54,7 @@ func TestRuby(t *testing.T) {
5154 rubinius-2.0.0-rc1` ,
5255 },
5356 {
57+ Case : "Version with asdf" ,
5458 ExpectedString : "2.6.3" ,
5559 ExpectedEnabled : true ,
5660 DisplayVersion : true ,
@@ -59,13 +63,23 @@ func TestRuby(t *testing.T) {
5963 Version : "ruby 2.6.3 /Users/jan/Projects/oh-my-posh3/.tool-versions" ,
6064 },
6165 {
66+ Case : "Version with asdf not set" ,
6267 ExpectedString : "" ,
63- ExpectedEnabled : false ,
68+ ExpectedEnabled : true ,
6469 DisplayVersion : true ,
6570 HasRubyFiles : true ,
6671 HasAsdf : true ,
6772 Version : "ruby ______ No version set. Run \" asdf <global|shell|local> ruby <version>\" " ,
6873 },
74+ {
75+ Case : "Version with ruby" ,
76+ ExpectedString : "2.6.3" ,
77+ ExpectedEnabled : true ,
78+ DisplayVersion : true ,
79+ HasRubyFiles : true ,
80+ HasRuby : true ,
81+ Version : "ruby 2.6.3 (2019-04-16 revision 67580) [universal.x86_64-darwin20]" ,
82+ },
6983 }
7084 for _ , tc := range cases {
7185 env := new (MockedEnvironment )
@@ -87,11 +101,9 @@ func TestRuby(t *testing.T) {
87101 DisplayVersion : tc .DisplayVersion ,
88102 },
89103 }
90- ruby := & ruby {
91- env : env ,
92- props : props ,
93- }
94- assert .Equal (t , tc .ExpectedEnabled , ruby .enabled (), fmt .Sprintf ("Failed in case: %+v" , tc ))
95- assert .Equal (t , tc .ExpectedString , ruby .string (), fmt .Sprintf ("Failed in case: %+v" , tc ))
104+ ruby := & ruby {}
105+ ruby .init (props , env )
106+ assert .Equal (t , tc .ExpectedEnabled , ruby .enabled (), fmt .Sprintf ("Failed in case: %s" , tc .Case ))
107+ assert .Equal (t , tc .ExpectedString , ruby .string (), fmt .Sprintf ("Failed in case: %s" , tc .Case ))
96108 }
97109}
0 commit comments