@@ -3,8 +3,13 @@ local stub = require("luassert.stub")
33local spy = require (" luassert.spy" )
44local match = require (" luassert.match" )
55local article = require (" forem-nvim.article" )
6+ local busted = require (" plenary.busted" )
7+ local describe = busted .describe
8+ local before_each = busted .before_each
9+ local after_each = busted .after_each
10+ local it = busted .it
611
7- local function mockInternal (module )
12+ local function mock_internal (module )
813 _G .package .loaded [" forem-nvim" ] = nil
914 _G .package .loaded [module ] = nil
1015 local mocked = require (module )
1419describe (
1520 " Forem.nvim" ,
1621 function ()
17- local foremNvim
22+ local forem_nvim
1823 local snapshot
24+
1925 before_each (function ()
2026 vim .env .FOREM_API_KEY = " foo"
2127 _G .package .loaded [" forem-nvim" ] = nil
22- foremNvim = require (" forem-nvim" )
28+ forem_nvim = require (" forem-nvim" )
2329 snapshot = assert :snapshot ()
2430 end )
31+
2532 after_each (function ()
2633 snapshot :revert ()
2734 end )
35+
2836 it (
2937 " should show a notification when no api key is set" ,
3038 function ()
3139 vim .env .FOREM_API_KEY = nil
3240 stub .new (vim , " notify" )
33- foremNvim .my_articles ()
41+ forem_nvim .my_articles ()
3442 assert .stub (vim .notify ).was .called ()
3543 end
3644 )
45+
3746 it (
3847 " should call the api to get the articles" ,
3948 function ()
40- local mockedApi = mockInternal (" forem-nvim.api" )
41- mockedApi . myArticles = spy .new (function ()
49+ local mocked_api = mock_internal (" forem-nvim.api" )
50+ mocked_api . my_articles = spy .new (function ()
4251 end )
43- local foremNvimMocked = require (" forem-nvim" )
44- foremNvimMocked .my_articles ()
45- assert .spy (mockedApi . myArticles ).was .called ()
52+ local forem_nvim_mocked = require (" forem-nvim" )
53+ forem_nvim_mocked .my_articles ()
54+ assert .spy (mocked_api . my_articles ).was .called ()
4655 end
4756 )
57+
4858 it (
4959 " should create a new article and open it" ,
5060 function ()
5161 local input = stub .new (vim .fn , " input" )
5262 input .returns (" Title" )
53- local api = mockInternal (" forem-nvim.api" )
54- local apiNewArticle = stub .new (api , " newArticle " )
55- local newArticle = {
63+ local api = mock_internal (" forem-nvim.api" )
64+ local api_new_article = stub .new (api , " new_article " )
65+ local new_article = {
5666 id = 1 ,
5767 body_markdown = article .get_template (" Title" )
5868 }
59- apiNewArticle .returns ({ status = 201 , body = newArticle })
60- local buffer = mockInternal (" forem-nvim.buffer" )
61- local bufferOpenMyArticle = spy .on (buffer , " openMyArticle " )
62- local foremNvimMocked = require (" forem-nvim" )
63- foremNvimMocked .new_article ()
64- assert .stub (apiNewArticle ).was .called_with (" Title" )
65- assert .spy (bufferOpenMyArticle ).was_called_with (match .is_same (newArticle ))
69+ api_new_article .returns ({ status = 201 , body = new_article })
70+ local buffer = mock_internal (" forem-nvim.buffer" )
71+ local buffer_open_my_article = spy .on (buffer , " open_my_article " )
72+ local forem_nvim_mocked = require (" forem-nvim" )
73+ forem_nvim_mocked .new_article ()
74+ assert .stub (api_new_article ).was .called_with (" Title" )
75+ assert .spy (buffer_open_my_article ).was_called_with (match .is_same (new_article ))
6676 assert .are .same (
67- " forem://my-article/" .. tostring (newArticle .id ),
77+ " forem://my-article/" .. tostring (new_article .id ),
6878 vim .api .nvim_buf_get_name (0 )
6979 )
70- local bufferContent = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , true )
80+ local buffer_content = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , true )
7181 assert .are .same (
72- article .get_body_lines (newArticle ),
73- bufferContent
82+ article .get_body_lines (new_article ),
83+ buffer_content
7484 )
7585 end
7686 )
0 commit comments