.. | ||
spec | ||
eval.fish | ||
expect.fish | ||
list.erase.fish | ||
README.md | ||
spec.eval.fish | ||
spec.functions.fish | ||
spec.run.fish | ||
spec.view.fish |
fish-spec
Unit testing as simple as fish.
The following guide describes how to use the fish-spec
plugin bundled with Oh-My-Fish.
Install
Before you can use fish-spec
, you need to install Oh-My-Fish.
Usage
Import the library into your fish file via import.
Inside your project's directory create a new spec
folder and add all your spec files inside. Spec files are regular fish files that shall look like *.spec.fish
and contain your tests.
You can have multiple spec.fish
files to organize your tests in a per module basis, or you can squash everything into a single file and use describe blocks to separate groups of tests.
A spec.file
usually looks like this:
import plugins/fish-spec
import plugins/the-library
# Use -d to enter a friendly description (optional)
function describe_library -d "the grand library"
function before_all
# Optional. Runs only once before all the tests.
end
function after_all
# Optional. Runs only once after all the tests.
end
function before_each
# Optional. Runs once before each test.
end
function after_each
# Optional. Runs once after each test.
end
function it_does_this
# ...
expect $what_I_got --to-equal $what_I_wanted
end
function it_does_that
# ...
expect $a_list --to-contain-all $expected_items
end
# ...
end
# Run tests when this file is sourced.
spec.run $argv
API
As of now, there is only one method you should be aware of, expect:
Assert a list of expected values match an actual value/s.
Under the hood, expect checks an actual value, usually a relevant result from your test unit, is equal to, not equal to, etc., to an expected value, as determined by your test. Below are the list of conditions available to use with expect
:
- --to-equal
<actual>
value equals the<expected>
value. For example:
expect $my_value --to-equal 5
- --to-not-equal
<actual>
value does not equal the<expected>
value
expect $my_string --to-not-equal "oh-the-fish"
- --to-contain-all all
<actual>
values exist in the<expected>
list
expect $elements --to-contain-all "earth" "fire" "water" "air"
- --to-not-contain-all no
<actual>
values exist in<expected>
list
expect $our_planets --to-not-not-contain-all "golomo" "borg prime" "rigel" "terra"
- --to-be-true the exit status should be truthy
__my_plugin_improve_workflow
expect $status --to-be-true
- --to-be-false the exit status should be falsy
__my_plugin_erase_drive
expect $status --to-be-false
FAQ
- How to use
fish-spec
without Oh-My-Fish?
fish-spec
is currently only available bundled with Oh-My-Fish. As the library matures and grows, however, a future guide describing how to exportfish-spec
may be written.