Skip to content

Commit d244ad2

Browse files
authored
Avoid stubbing File.read to prevent flaky tests (#2980)
### Motivation This test is flaky because sometimes threads switch and something else tries to invoke `File.read`. Instead of stubbing it, we can just create the expected file to avoid the flakiness.
1 parent 4a300d1 commit d244ad2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/server_test.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,21 @@ def test_backtrace_is_printed_to_stderr_on_exceptions
439439
end
440440

441441
def test_changed_file_only_indexes_ruby
442-
File.expects(:read).with("/foo.rb").returns("class Foo\nend")
442+
path = File.join(Dir.pwd, "lib", "foo.rb")
443+
File.write(path, "class Foo\nend")
444+
443445
@server.global_state.index.expects(:index_single).once.with do |uri|
444-
uri.full_path == "/foo.rb"
446+
uri.full_path == path
445447
end
448+
449+
uri = URI::Generic.from_path(path: path)
450+
446451
@server.process_message({
447452
method: "workspace/didChangeWatchedFiles",
448453
params: {
449454
changes: [
450455
{
451-
uri: URI("file:///foo.rb"),
456+
uri: uri,
452457
type: RubyLsp::Constant::FileChangeType::CREATED,
453458
},
454459
{
@@ -458,6 +463,8 @@ def test_changed_file_only_indexes_ruby
458463
],
459464
},
460465
})
466+
ensure
467+
FileUtils.rm(T.must(path))
461468
end
462469

463470
def test_workspace_addons

0 commit comments

Comments
 (0)