1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
local spy = require "luassert.spy"
local stub = require "luassert.stub"
local match = require "luassert.match"
local mock = require "luassert.mock"
local installer = require "mason-core.installer"
local gem = require "mason-core.managers.gem"
local Result = require "mason-core.result"
local spawn = require "mason-core.spawn"
local api = require "mason-registry.api"
local _ = require "mason-core.functional"
describe("gem manager", function()
it(
"should call gem install",
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
installer.prepare_installer(ctx)
installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.spy(ctx.spawn.gem).was_called(1)
assert.spy(ctx.spawn.gem).was_called_with(match.tbl_containing {
"install",
"--no-user-install",
"--no-format-executable",
"--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()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { version = "42.13.37" })
installer.prepare_installer(ctx)
installer.exec_in_context(ctx, gem.packages { "main-package", "supporting-package", "supporting-package2" })
assert.same({
type = "gem",
package = "main-package",
}, ctx.receipt.primary_source)
assert.same({
{
type = "gem",
package = "supporting-package",
},
{
type = "gem",
package = "supporting-package2",
},
}, ctx.receipt.secondary_sources)
end)
)
end)
describe("gem version check", function()
it(
"should return current version",
async_test(function()
stub(spawn, "gem")
spawn.gem.returns(Result.success {
stdout = _.dedent [[
shellwords (default: 0.1.0)
singleton (default: 0.1.1)
solargraph (0.44.0)
stringio (default: 3.0.1)
strscan (default: 3.0.1)
]],
})
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.tbl_containing {
GEM_HOME = "/tmp/install/dir",
GEM_PATH = "/tmp/install/dir",
PATH = match.matches "^/tmp/install/dir/bin:.*$",
},
})
assert.is_true(result:is_success())
assert.equals("0.44.0", result:get_or_nil())
end)
)
it(
"should return outdated primary package",
async_test(function()
stub(spawn, "gem")
spawn.gem.returns(Result.success {
stdout = _.dedent [[
shellwords (default: 0.1.0)
singleton (default: 0.1.1)
solargraph (0.44.0)
stringio (default: 3.0.1)
strscan (default: 3.0.1)
]],
})
stub(api, "get")
api.get.on_call_with("/api/rubygems/solargraph/versions/latest").returns(Result.success {
name = "solargraph",
version = "0.44.3",
})
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_success())
assert.same({
name = "solargraph",
current_version = "0.44.0",
latest_version = "0.44.3",
}, result:get_or_nil())
end)
)
it(
"should return failure if primary package is not outdated",
async_test(function()
stub(spawn, "gem")
spawn.gem.returns(Result.success {
stdout = _.dedent [[
shellwords (default: 0.1.0)
singleton (default: 0.1.1)
solargraph (0.44.0)
stringio (default: 3.0.1)
strscan (default: 3.0.1)
]],
})
stub(api, "get")
api.get.on_call_with("/api/rubygems/solargraph/versions/latest").returns(Result.success {
name = "solargraph",
version = "0.44.0",
})
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())
end)
)
it("should parse gem list output", function()
assert.same(
{
["solargraph"] = "0.44.3",
["unicode-display_width"] = "2.1.0",
},
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)
|