diff options
| author | William Boman <william@redwill.se> | 2022-03-26 13:41:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-26 13:41:50 +0100 |
| commit | 212d17a039da449043b67529c29851db37acc236 (patch) | |
| tree | 38411b14487895cef0d7648e198b79fd28793fe6 /tests/core/managers/gem_spec.lua | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-212d17a039da449043b67529c29851db37acc236.tar mason-212d17a039da449043b67529c29851db37acc236.tar.gz mason-212d17a039da449043b67529c29851db37acc236.tar.bz2 mason-212d17a039da449043b67529c29851db37acc236.tar.lz mason-212d17a039da449043b67529c29851db37acc236.tar.xz mason-212d17a039da449043b67529c29851db37acc236.tar.zst mason-212d17a039da449043b67529c29851db37acc236.zip | |
add async managers (#536)
Diffstat (limited to 'tests/core/managers/gem_spec.lua')
| -rw-r--r-- | tests/core/managers/gem_spec.lua | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/tests/core/managers/gem_spec.lua b/tests/core/managers/gem_spec.lua new file mode 100644 index 00000000..e258c65b --- /dev/null +++ b/tests/core/managers/gem_spec.lua @@ -0,0 +1,226 @@ +local spy = require "luassert.spy" +local match = require "luassert.match" +local mock = require "luassert.mock" +local Optional = require "nvim-lsp-installer.core.optional" +local gem = require "nvim-lsp-installer.core.managers.gem" +local Result = require "nvim-lsp-installer.core.result" +local spawn = require "nvim-lsp-installer.core.spawn" + +describe("gem manager", function() + ---@type InstallContext + local ctx + before_each(function() + ctx = InstallContextGenerator { + spawn = mock.new { + gem = mockx.returns {}, + }, + } + end) + + it( + "should call gem install", + async_test(function() + ctx.requested_version = Optional.of "42.13.37" + gem.packages { "main-package", "supporting-package", "supporting-package2" }(ctx) + assert.spy(ctx.spawn.gem).was_called(1) + assert.spy(ctx.spawn.gem).was_called_with(match.tbl_containing { + "install", + "--no-user-install", + "--install-dir=.", + "--bindir=bin", + "--no-document", + match.tbl_containing { + "main-package:42.13.37", + "supporting-package", + "supporting-package2", + }, + }) + end) + ) + + it( + "should provide receipt information", + async_test(function() + ctx.requested_version = Optional.of "42.13.37" + gem.packages { "main-package", "supporting-package", "supporting-package2" }(ctx) + assert.equals( + vim.inspect { + type = "gem", + package = "main-package", + }, + vim.inspect(ctx.receipt.primary_source) + ) + assert.equals( + vim.inspect { + { + type = "gem", + package = "supporting-package", + }, + { + type = "gem", + package = "supporting-package2", + }, + }, + vim.inspect(ctx.receipt.secondary_sources) + ) + end) + ) +end) + +describe("gem version check", function() + it( + "should return current version", + async_test(function() + spawn.gem = spy.new(function() + return Result.success { + stdout = [[shellwords (default: 0.1.0) +singleton (default: 0.1.1) +solargraph (0.44.0) +stringio (default: 3.0.1) +strscan (default: 3.0.1) +]], + } + end) + + local result = gem.get_installed_primary_package_version( + mock.new { + primary_source = mock.new { + type = "gem", + package = "solargraph", + }, + }, + "/tmp/install/dir" + ) + + assert.spy(spawn.gem).was_called(1) + assert.spy(spawn.gem).was_called_with(match.tbl_containing { + "list", + cwd = "/tmp/install/dir", + env = match.all_of( + match.list_containing "GEM_HOME=/tmp/install/dir", + match.list_containing "GEM_PATH=/tmp/install/dir" + ), + }) + assert.is_true(result:is_success()) + assert.equals("0.44.0", result:get_or_nil()) + + spawn.gem = nil + end) + ) + + it( + "should return outdated primary package", + async_test(function() + spawn.gem = spy.new(function() + return Result.success { + stdout = [[bigdecimal (3.1.1 < 3.1.2) +cgi (0.3.1 < 0.3.2) +logger (1.5.0 < 1.5.1) +ostruct (0.5.2 < 0.5.3) +reline (0.3.0 < 0.3.1) +securerandom (0.1.1 < 0.2.0) +solargraph (0.44.0 < 0.44.3) +]], + } + end) + + local result = gem.check_outdated_primary_package( + mock.new { + primary_source = mock.new { + type = "gem", + package = "solargraph", + }, + }, + "/tmp/install/dir" + ) + + assert.spy(spawn.gem).was_called(1) + assert.spy(spawn.gem).was_called_with(match.tbl_containing { + "outdated", + cwd = "/tmp/install/dir", + env = match.all_of( + match.list_containing "GEM_HOME=/tmp/install/dir", + match.list_containing "GEM_PATH=/tmp/install/dir" + ), + }) + assert.is_true(result:is_success()) + assert.equals( + vim.inspect { + name = "solargraph", + current_version = "0.44.0", + latest_version = "0.44.3", + }, + vim.inspect(result:get_or_nil()) + ) + + spawn.gem = nil + end) + ) + + it( + "should return failure if primary package is not outdated", + async_test(function() + spawn.gem = spy.new(function() + return Result.success { + stdout = "", + } + end) + + local result = gem.check_outdated_primary_package( + mock.new { + primary_source = mock.new { + type = "gem", + package = "solargraph", + }, + }, + "/tmp/install/dir" + ) + + assert.is_true(result:is_failure()) + assert.equals("Primary package is not outdated.", result:err_or_nil()) + spawn.gem = nil + end) + ) + + it("parses outdated gem output", function() + local normalize = gem.parse_outdated_gem + assert.equal( + vim.inspect { + name = "solargraph", + current_version = "0.42.2", + latest_version = "0.44.2", + }, + vim.inspect(normalize [[solargraph (0.42.2 < 0.44.2)]]) + ) + assert.equal( + vim.inspect { + name = "sorbet-runtime", + current_version = "0.5.9307", + latest_version = "0.5.9468", + }, + vim.inspect(normalize [[sorbet-runtime (0.5.9307 < 0.5.9468)]]) + ) + end) + + it("returns nil when unable to parse outdated gem", function() + assert.is_nil(gem.parse_outdated_gem "a whole bunch of gibberish!") + assert.is_nil(gem.parse_outdated_gem "") + end) + + it("should parse gem list output", function() + assert.equals( + vim.inspect { + ["solargraph"] = "0.44.3", + ["unicode-display_width"] = "2.1.0", + }, + vim.inspect(gem.parse_gem_list_output [[ + +*** LOCAL GEMS *** + +nokogiri (1.13.3 arm64-darwin) +solargraph (0.44.3) +unicode-display_width (2.1.0) +]]) + ) + end) +end) |
