oh-my-fish/plugins/fish-spec
2015-02-01 13:50:48 +09:00
..
spec simplifying expect tests 2015-01-20 22:18:20 -02:00
eval.fish ⌁ Update Fish-Spec ⌁ 2015-01-17 13:46:44 +09:00
expect.fish allow debugging messages to be echoed inside a test 2015-01-17 18:07:49 -02:00
list.erase.fish ⌁ Update Fish-Spec ⌁ 2015-01-17 13:46:44 +09:00
README.md Rename .markdown to .md; add links to plugins and fix typos. 2015-02-01 13:50:48 +09:00
spec.eval.fish allow debugging messages to be echoed inside a test 2015-01-17 18:07:49 -02:00
spec.functions.fish ⌁ Update Fish-Spec ⌁ 2015-01-17 13:46:44 +09:00
spec.run.fish allow debugging messages to be echoed inside a test 2015-01-17 18:07:49 -02:00
spec.view.fish ⌁ Update Fish-Spec ⌁ 2015-01-17 13:46:44 +09:00

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

  1. 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 export fish-spec may be written.

Authors

License

MIT