SqJasmine is a Behavior-Driven Development testing framework for Squirrel.
This is a partial Squirrel port of Jasmine by Simon Lundmark written for behavior-driven development on the Electric Imp platform.
It's all in documentation-spec.nut
. There you will find the ported version of the Jasmine Documentation. That file also doubles as the test suite of SqJasmine.
To use SqJasmine in your Electric Imp project, simply copy and paste the contents of sqjasmine.nut
to the top the model in the Electric Imp IDE. Happy testing!
SqJasmine's development is test-driven by basically copying and pasting the JavaScript code examples from the Jasmine Documentation, translating them to Squirrel code (not much to change at all), running it then finally implementing enough of the Jasmine API until it runs without runtime errors :) Lots of fun!
Local development works like a charm, for example this will run the self-testing suite on a Mac:
$ brew install squirrel
/.../
$ sq documentation-spec.nut
A suite
contains spec with one or more expectations
A failing suite
contains spec with a failing expectation
A suite is just a function
and so is a spec
The 'toBe' matcher compares
and has a positive case
and can have a negative case
Included matchers:
The 'toBe' matcher compares with ==
The 'toEqual' matcher
works for simple literals and variables
works for negative testing simple literals and variables
can fail for simple literals and variables
can fail for negatively tested simple literals and variables
handles tables:
can be empty
requires tables to be of the same sizes
needs to contain the same data
needs to contain the same keys
can be negated:
can detect different values of the same slot
can detect different number of slots
can detect same number of slots but with different keys
can contain more simple data
can contain nested tables
can be equal
can negatively test nested tables
can fail for nested tables
A spec
is just a function, so it can contain any code
can have more than one expectation
Automatically running the tests on source code file save is an incredible productivity boost. Here's how it can be done using entr on a Mac:
$ brew install entr
$ find . -name '*.nut' | entr -c bash -c 'sq helper-specs.nut && sq documentation-specs.nut'