From ffec552e787510b8ce9187d0f743da345e0d34a5 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 16 Aug 2024 16:44:40 -0400 Subject: [PATCH] WIP --- .../src/test/suite/ruby/rubyInstaller.test.ts | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/vscode/src/test/suite/ruby/rubyInstaller.test.ts b/vscode/src/test/suite/ruby/rubyInstaller.test.ts index 6775316975..ea5bf473be 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,43 @@ 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( + 'powershell -Command \\"(Get-Command pwsh.exe).Path\\"', + ); + // eslint-disable-next-line no-console + console.log(stdout); + 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, + }); + }); });