Skip to content

Commit

Permalink
proper testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyshear committed Nov 17, 2024
1 parent 4b7950c commit 421cd84
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
_all = {
coverage = false,
lpath = 'lua/?.lua;lua/?/init.lua',
lua = './test/busted.lua',
},
default = {
verbose = true,
},
tests = {
verbose = true,
},
}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ jobs:
shell: bash
run: |
luarocks install luacheck
luarocks install vusted
vusted ./test
luarocks install busted
busted ./test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tests/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ The CI uses `stylua` to format the code; customize the formatting by editing `.s

### Test

Uses [busted](https://lunarmodules.github.io/busted/) for testing. Installs by using `luarocks --lua-version=5.1 install vusted` then runs `vusted ./test`
for your test cases. `vusted` is a wrapper of Busted especially for testing Neovim plugins.
Uses [busted](https://lunarmodules.github.io/busted/) for testing. Installs by using `luarocks --lua-version=5.1 install busted` then runs `busted ./test`
for your test cases.

Create test cases in the `test` folder. Busted expects files in this directory to be named `foo_spec.lua`, with `_spec` as a suffix before the `.lua` file extension. For more usage details please check
[busted usage](https://lunarmodules.github.io/busted/)

### CI

- Auto generates doc from README.
- Runs the Busted/vusted integration tests
- Runs the Busted integration tests
- Lints with `stylua`.
4 changes: 4 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
drash-drash.nvim drash.txt /*drash-drash.nvim*
drash-drash.nvim-development drash.txt /*drash-drash.nvim-development*
drash-table-of-contents drash.txt /*drash-table-of-contents*
drash.txt drash.txt /*drash.txt*
2 changes: 2 additions & 0 deletions lua/drash/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local sefaria = require('drash.sefaria')
_ = sefaria
local M = {}

M.setup = function(spec, opts)
Expand Down
20 changes: 20 additions & 0 deletions lua/drash/sefaria.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local plenary_curl = require('plenary.curl')

local M = {}

M.get_calendar = function()
local url = 'https://www.sefaria.org/api/calendars'

local response = plenary_curl.get(url)

if response.status ~= 200 then
return nil
end

local body = response.body
local data = vim.json.decode(body)

return data
end

return M
11 changes: 11 additions & 0 deletions test/busted.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env -S nvim -l

vim.env.LAZY_STDPATH = '.tests'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

-- Setup lazy.nvim
require('lazy.minit').busted({
spec = {
'nvim-lua/plenary.nvim',
},
})
1 change: 0 additions & 1 deletion test/plugin_spec.lua

This file was deleted.

10 changes: 10 additions & 0 deletions test/sefaria_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local sefaria = require('drash.sefaria')

describe('sefaria', function()
it('should return a table', function()
assert.are.same(type(sefaria.get_calendar()), 'table')
end)
it('should return a table with a key of "calendar_items"', function()
assert.are.same(type(sefaria.get_calendar().calendar_items), 'table')
end)
end)

0 comments on commit 421cd84

Please sign in to comment.