diff --git a/spec/async_integration_spec.lua b/spec/async_integration_spec.lua index 7a90ce1..dd4c523 100644 --- a/spec/async_integration_spec.lua +++ b/spec/async_integration_spec.lua @@ -75,10 +75,15 @@ describe('async integration', function() end, } - vim.cmd = { + local cmd_methods = { e = function() end, only = function() end, + startinsert = function() end, + stopinsert = function() end, } + vim.cmd = setmetatable(function() end, { + __index = cmd_methods, + }) vim.api.nvim_get_current_buf = function() return 1 end diff --git a/spec/async_setup_spec.lua b/spec/async_setup_spec.lua index 2f2fd83..f6b9904 100644 --- a/spec/async_setup_spec.lua +++ b/spec/async_setup_spec.lua @@ -20,7 +20,7 @@ describe('cp.async.setup', function() }, }) end, - scrape_problem_async = function(platform, contest_id, problem_id, callback) + scrape_problem_async = function(_, _, problem_id, callback) callback({ success = true, problem_id = problem_id, @@ -69,10 +69,15 @@ describe('cp.async.setup', function() end, } - vim.cmd = { + local cmd_methods = { e = function() end, only = function() end, + startinsert = function() end, + stopinsert = function() end, } + vim.cmd = setmetatable(function() end, { + __index = cmd_methods, + }) vim.api.nvim_get_current_buf = function() return 1 end diff --git a/spec/cache_spec.lua b/spec/cache_spec.lua index a72946a..2f5053a 100644 --- a/spec/cache_spec.lua +++ b/spec/cache_spec.lua @@ -4,6 +4,19 @@ describe('cp.cache', function() before_each(function() spec_helper.setup() + + local mock_file_content = '{}' + vim.fn.filereadable = function() + return 1 + end + vim.fn.readfile = function() + return { mock_file_content } + end + vim.fn.writefile = function(lines) + mock_file_content = table.concat(lines, '\n') + end + vim.fn.mkdir = function() end + cache = require('cp.cache') cache.load() end) diff --git a/spec/command_parsing_spec.lua b/spec/command_parsing_spec.lua index 693f2b2..f37eb15 100644 --- a/spec/command_parsing_spec.lua +++ b/spec/command_parsing_spec.lua @@ -12,6 +12,29 @@ describe('cp command parsing', function() } package.loaded['cp.log'] = mock_logger + local mock_async_setup = { + setup_contest_async = function() end, + handle_full_setup_async = function() end, + setup_problem_async = function() end, + } + package.loaded['cp.async.setup'] = mock_async_setup + local mock_setup = { + set_platform = function() + return true + end, + } + package.loaded['cp.setup'] = mock_setup + + local mock_state = { + get_platform = function() + return 'atcoder' + end, + get_contest_id = function() + return 'abc123' + end, + } + package.loaded['cp.state'] = mock_state + cp = require('cp') cp.setup({ contests = { @@ -29,6 +52,9 @@ describe('cp command parsing', function() after_each(function() package.loaded['cp.log'] = nil + package.loaded['cp.async.setup'] = nil + package.loaded['cp.setup'] = nil + package.loaded['cp.state'] = nil end) describe('empty arguments', function()