@@ -3,8 +3,13 @@ local stub = require("luassert.stub")
3
3
local spy = require (" luassert.spy" )
4
4
local match = require (" luassert.match" )
5
5
local 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
6
11
7
- local function mockInternal (module )
12
+ local function mock_internal (module )
8
13
_G .package .loaded [" forem-nvim" ] = nil
9
14
_G .package .loaded [module ] = nil
10
15
local mocked = require (module )
14
19
describe (
15
20
" Forem.nvim" ,
16
21
function ()
17
- local foremNvim
22
+ local forem_nvim
18
23
local snapshot
24
+
19
25
before_each (function ()
20
26
vim .env .FOREM_API_KEY = " foo"
21
27
_G .package .loaded [" forem-nvim" ] = nil
22
- foremNvim = require (" forem-nvim" )
28
+ forem_nvim = require (" forem-nvim" )
23
29
snapshot = assert :snapshot ()
24
30
end )
31
+
25
32
after_each (function ()
26
33
snapshot :revert ()
27
34
end )
35
+
28
36
it (
29
37
" should show a notification when no api key is set" ,
30
38
function ()
31
39
vim .env .FOREM_API_KEY = nil
32
40
stub .new (vim , " notify" )
33
- foremNvim .my_articles ()
41
+ forem_nvim .my_articles ()
34
42
assert .stub (vim .notify ).was .called ()
35
43
end
36
44
)
45
+
37
46
it (
38
47
" should call the api to get the articles" ,
39
48
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 ()
42
51
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 ()
46
55
end
47
56
)
57
+
48
58
it (
49
59
" should create a new article and open it" ,
50
60
function ()
51
61
local input = stub .new (vim .fn , " input" )
52
62
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 = {
56
66
id = 1 ,
57
67
body_markdown = article .get_template (" Title" )
58
68
}
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 ))
66
76
assert .are .same (
67
- " forem://my-article/" .. tostring (newArticle .id ),
77
+ " forem://my-article/" .. tostring (new_article .id ),
68
78
vim .api .nvim_buf_get_name (0 )
69
79
)
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 )
71
81
assert .are .same (
72
- article .get_body_lines (newArticle ),
73
- bufferContent
82
+ article .get_body_lines (new_article ),
83
+ buffer_content
74
84
)
75
85
end
76
86
)
0 commit comments