Skip to content

Commit

Permalink
Avoid stubbing File.read to prevent flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Dec 12, 2024
1 parent 8671a04 commit 368ae14
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand All @@ -458,6 +463,8 @@ def test_changed_file_only_indexes_ruby
],
},
})
ensure
FileUtils.rm(T.must(path))
end

def test_workspace_addons
Expand Down

0 comments on commit 368ae14

Please sign in to comment.