aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers/lua/test_helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers/lua/test_helpers.lua')
-rw-r--r--tests/helpers/lua/test_helpers.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua
index 5e38639..15ccd5e 100644
--- a/tests/helpers/lua/test_helpers.lua
+++ b/tests/helpers/lua/test_helpers.lua
@@ -16,6 +16,25 @@ function async_test(suspend_fn)
end
end
+local TableMock = {}
+TableMock.__index = TableMock
+
+function TableMock.new(tbl, key)
+ return setmetatable({
+ tbl = tbl,
+ key = key,
+ }, TableMock)
+end
+
+function TableMock:apply(value)
+ self.original_value = self.tbl[self.key]
+ self.tbl[self.key] = value
+end
+
+function TableMock:revert()
+ self.tbl[self.key] = self.original_value
+end
+
-- selene: allow(incorrect_standard_library_use)
mockx = {
just_runs = function() end,
@@ -29,6 +48,12 @@ mockx = {
error(exception, 2)
end
end,
+ table = function(tbl, key, new_value)
+ local mock = TableMock.new(tbl, key)
+ mock:apply(new_value)
+ assert:add_spy(mock)
+ return mock
+ end,
}
---@param package_name string