From 368ae1463909c05be3d56934c4e636beb2c19cff Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 12 Dec 2024 14:16:56 -0500 Subject: [PATCH] Avoid stubbing File.read to prevent flaky tests --- test/server_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/server_test.rb b/test/server_test.rb index ba042c199..fae9bef5a 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -439,16 +439,21 @@ def test_backtrace_is_printed_to_stderr_on_exceptions end def test_changed_file_only_indexes_ruby - File.expects(:read).with("/foo.rb").returns("class Foo\nend") + path = File.join(Dir.pwd, "lib", "foo.rb") + File.write(path, "class Foo\nend") + @server.global_state.index.expects(:index_single).once.with do |uri| - uri.full_path == "/foo.rb" + uri.full_path == path end + + uri = URI::Generic.from_path(path: path) + @server.process_message({ method: "workspace/didChangeWatchedFiles", params: { changes: [ { - uri: URI("file:///foo.rb"), + uri: uri, type: RubyLsp::Constant::FileChangeType::CREATED, }, { @@ -458,6 +463,8 @@ def test_changed_file_only_indexes_ruby ], }, }) + ensure + FileUtils.rm(T.must(path)) end def test_workspace_addons