diff --git a/vscode/src/test/suite/ruby/rubyInstaller.test.ts b/vscode/src/test/suite/ruby/rubyInstaller.test.ts index 6775316975..8dc5e14b80 100644 --- a/vscode/src/test/suite/ruby/rubyInstaller.test.ts +++ b/vscode/src/test/suite/ruby/rubyInstaller.test.ts @@ -3,12 +3,13 @@ import assert from "assert"; import path from "path"; import os from "os"; +import sinon from "sinon"; import { before, after } from "mocha"; import * as vscode from "vscode"; import { RubyInstaller } from "../../../ruby/rubyInstaller"; import { WorkspaceChannel } from "../../../workspaceChannel"; -import { LOG_CHANNEL } from "../../../common"; +import { asyncExec, LOG_CHANNEL } from "../../../common"; import { RUBY_VERSION } from "../../rubyVersion"; suite("RubyInstaller", () => { @@ -100,4 +101,39 @@ suite("RubyInstaller", () => { force: true, }); }); + + test("Finds Ruby using Powershell", async () => { + const [major, minor, _patch] = RUBY_VERSION.split(".").map(Number); + fs.symlinkSync( + path.join( + "C:", + "hostedtoolcache", + "windows", + "Ruby", + RUBY_VERSION, + "x64", + ), + path.join("C:", `Ruby${major}${minor}-${os.arch()}`), + ); + + fs.writeFileSync(path.join(workspacePath, ".ruby-version"), RUBY_VERSION); + + const windows = new RubyInstaller(workspaceFolder, outputChannel); + + const { stdout } = await asyncExec("where powershell"); + const stub = sinon.stub(vscode.env, "shell").returns(stdout.trim()); + + const { env, version, yjit } = await windows.activate(); + stub.restore(); + + assert.match(env.GEM_PATH!, /ruby\/3\.3\.0/); + assert.match(env.GEM_PATH!, /lib\/ruby\/gems\/3\.3\.0/); + assert.strictEqual(version, RUBY_VERSION); + assert.notStrictEqual(yjit, undefined); + + fs.rmSync(path.join("C:", `Ruby${major}${minor}-${os.arch()}`), { + recursive: true, + force: true, + }); + }); });