A wrapper that tweaks LuaUnit for a more pleasant test writing experience with Fennel.
To install through fnx, add to your .fnx.fnl
:
:fspec {:fennel/fnx {:git/github "gbaptista/fspec"}}
; Example:
{:name "my-project"
:version "0.0.1"
:dependencies {
:fspec {:fennel/fnx {:git/github "gbaptista/fspec"}}}}
And install:
fnx dep install
Create a some_test.fnl
file:
(local t (require :fspec))
(t.eq "actual" "expected")
(t.is-number "1.2")
(t.run!)
Run with:
fnx some_test.fnl
To run all _test.fnl
tests, create a test.fnl
file with:
(local t (require :fspec))
(t.run-all! "./")
And run:
fnx test.fnl
To use a different pattern, like _spec
, use:
(t.run-all! "./" "_spec")
To get a complete stack trace, use the --verbose
option:
fnx test.fnl --verbose
Check the dsl.fnl file for a list of all assertions available.
With LuaUnit you would write a test in Fennel like this:
(local luaunit (require :luaunit))
(fn testSomething []
(luaunit.assertEquals
{:title "actual" :value 17.89 }
{:title "expected" :value 12.0
:items [
"a" "b" "c" "d" "e"
"f" "g" "h" "i" "j"]}))
(os.exit (luaunit.LuaUnit.run))
With fspec you would write the same test as:
(local t (require :fspec))
(t.eq
{:title "actual" :value 17.89 }
{:title "expected" :value 12.0
:items [
"a" "b" "c" "d" "e"
"f" "g" "h" "i" "j"]})
(t.run!)
Which would result in: