Skip to content

Commit

Permalink
Fix tests, mock was not reverted
Browse files Browse the repository at this point in the history
beeender committed Jan 10, 2025
1 parent cada003 commit 47e9108
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/spec/binary_spec.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local binary = require("richclip.binary")
local stub = require('luassert.stub')

describe("ser tests", function()
describe("binary tests", function()
it('exec_richclip', function()
local str = ""
local stub_get_path = stub(binary, "get_richclip_exe_path")
stub_get_path.returns("echo")
-- The executed command is 'echo -n abc "cde\nefg'
str = binary.exec_richclip({ "-n", "abc", "cde\nefg" })
assert.equal(str, "abc cde\nefg")
stub_get_path.revert(stub_get_path)
end)

it('exec_richclip_async', function()
@@ -21,6 +22,7 @@ describe("ser tests", function()
sysobj:write(nil)
sysobj:wait()
assert.equal(str, "some\nthing")
stub_get_path.revert(stub_get_path)
end)

it('get_richclip_exe_path', function()
@@ -40,7 +42,7 @@ describe("ser tests", function()
binary._minor_ver, binary._patch_ver)
config.richclip_path = mock_richclip_path;
local path = binary.get_richclip_exe_path()
assert.equal(path, mock_richclip_path)
assert.equal(mock_richclip_path, path)

-- Test an valid exe in the PATH
binary._exe_path = nil
@@ -49,7 +51,7 @@ describe("ser tests", function()
vim.env.PATH = mock_richclip_dir .. ":" .. vim.env.PATH
path = binary.get_richclip_exe_path()
-- It is in the PATH, no need for absolute path
assert.equal(path, "richclip")
assert.equal("richclip", path)
vim.env.PATH = path_saved
end)

0 comments on commit 47e9108

Please sign in to comment.