6
6
7
7
class SetupBundlerTest < Minitest ::Test
8
8
def test_does_nothing_when_running_in_the_ruby_lsp
9
- Object . any_instance . expects ( :system ) . with ( bundle_install_command )
9
+ Object . any_instance . expects ( :system ) . with ( bundle_env , "bundle install 1>&2" )
10
10
run_script ( "/some/path/ruby-lsp" )
11
11
refute_path_exists ( ".ruby-lsp" )
12
12
end
13
13
14
14
def test_does_nothing_if_both_ruby_lsp_and_debug_are_in_the_bundle
15
- Object . any_instance . expects ( :system ) . with ( bundle_install_command )
15
+ Object . any_instance . expects ( :system ) . with ( bundle_env , "bundle install 1>&2" )
16
16
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { "ruby-lsp" => true , "debug" => true } )
17
17
run_script
18
18
refute_path_exists ( ".ruby-lsp" )
19
19
end
20
20
21
21
def test_removes_ruby_lsp_folder_if_both_gems_were_added_to_the_bundle
22
- Object . any_instance . expects ( :system ) . with ( bundle_install_command )
22
+ Object . any_instance . expects ( :system ) . with ( bundle_env , "bundle install 1>&2" )
23
23
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { "ruby-lsp" => true , "debug" => true } )
24
24
FileUtils . mkdir ( ".ruby-lsp" )
25
25
run_script
@@ -29,7 +29,7 @@ def test_removes_ruby_lsp_folder_if_both_gems_were_added_to_the_bundle
29
29
end
30
30
31
31
def test_creates_custom_bundle
32
- Object . any_instance . expects ( :system ) . with ( bundle_install_command ( ".ruby-lsp/Gemfile" ) )
32
+ Object . any_instance . expects ( :system ) . with ( bundle_env ( ".ruby-lsp/Gemfile" ) , "bundle install 1>&2" )
33
33
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { } )
34
34
run_script
35
35
@@ -43,7 +43,7 @@ def test_creates_custom_bundle
43
43
end
44
44
45
45
def test_copies_gemfile_lock_when_modified
46
- Object . any_instance . expects ( :system ) . with ( bundle_install_command ( ".ruby-lsp/Gemfile" ) )
46
+ Object . any_instance . expects ( :system ) . with ( bundle_env ( ".ruby-lsp/Gemfile" ) , "bundle install 1>&2" )
47
47
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { } ) . twice
48
48
FileUtils . mkdir ( ".ruby-lsp" )
49
49
FileUtils . touch ( ".ruby-lsp/Gemfile.lock" )
@@ -59,7 +59,7 @@ def test_copies_gemfile_lock_when_modified
59
59
end
60
60
61
61
def test_does_not_copy_gemfile_lock_when_not_modified
62
- Object . any_instance . expects ( :system ) . with ( bundle_install_command ( ".ruby-lsp/Gemfile" ) )
62
+ Object . any_instance . expects ( :system ) . with ( bundle_env ( ".ruby-lsp/Gemfile" ) , "bundle install 1>&2" )
63
63
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { } ) . twice
64
64
FileUtils . mkdir ( ".ruby-lsp" )
65
65
FileUtils . cp ( "Gemfile.lock" , ".ruby-lsp/Gemfile.lock" )
@@ -71,7 +71,7 @@ def test_does_not_copy_gemfile_lock_when_not_modified
71
71
72
72
def test_uses_absolute_bundle_path_for_bundle_install
73
73
Bundler . settings . set_global ( "path" , "vendor/bundle" )
74
- Object . any_instance . expects ( :system ) . with ( bundle_install_command ( ".ruby-lsp/Gemfile" ) )
74
+ Object . any_instance . expects ( :system ) . with ( bundle_env ( ".ruby-lsp/Gemfile" ) , "bundle install 1>&2" )
75
75
Bundler ::LockfileParser . any_instance . expects ( :dependencies ) . returns ( { } )
76
76
run_script
77
77
ensure
@@ -88,13 +88,12 @@ def run_script(path = "/fake/project/path")
88
88
RubyLsp ::SetupBundler . new ( path ) . setup!
89
89
end
90
90
91
- def bundle_install_command ( bundle_gemfile = nil )
91
+ def bundle_env ( bundle_gemfile = nil )
92
92
path = Bundler . settings [ "path" ]
93
93
94
- command = +""
95
- command << "BUNDLE_PATH=#{ File . expand_path ( path , Dir . pwd ) } " if path
96
- command << "BUNDLE_GEMFILE=#{ bundle_gemfile } " if bundle_gemfile
97
- command << "bundle install "
98
- command << "1>&2"
94
+ env = { }
95
+ env [ "BUNDLE_PATH" ] = File . expand_path ( path , Dir . pwd ) if path
96
+ env [ "BUNDLE_GEMFILE" ] = bundle_gemfile if bundle_gemfile
97
+ env
99
98
end
100
99
end
0 commit comments