a simple spec framework for Loom
LoomScript Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
LICENSE
README.md
Rakefile
terminal.png

README.md

spec-ls

a simple specification framework for Loom

spec-ls screenshot

installation

Download the library into its matching sdk folder:

$ curl -L -o ~/.loom/sdks/sprint34/libs/Spec.loomlib \
    https://github.com/pixeldroid/spec-ls/releases/download/v1.3.1/Spec-sprint34.loomlib

To uninstall, simply delete the file:

$ rm ~/.loom/sdks/sprint34/libs/Spec.loomlib

usage

  1. import Spec, a Reporter, and your specifications
  2. have the specifications describe themselves to Spec
  3. add your reporter(s) to Spec and execute
package
{
    import loom.Application;

    import pixeldroid.bdd.Spec;
    import pixeldroid.bdd.reporters.ConsoleReporter;


    public class SpecTest extends Application
    {

        override public function run():void
        {
            MySpec.describe();

            Spec.addReporter(new ConsoleReporter());
            Spec.execute();
        }
    }


    import pixeldroid.bdd.Thing;

    public static class MySpec
    {
        public static function describe():void
        {
            var it:Thing = Spec.describe('a Thing');

            it.should('exist', function() {
                it.expects(MySpec).not.toBeNull();
            });
        }
    }

}

TIP: use SpecExecutor; it has convenience methods to set reporter formats and seed values. See SpecTest for an example.

matchers

spec-ls has a basic set of expectation phrases for specifying behavior:

  • toBeA(type:Type)
  • toBeEmpty()
  • toBeFalsey() / toBeTruthy()
  • toBeGreaterThan(value2:Number) / toBeLessThan(value2:Number)
  • toBeNaN()
  • toBeNull()
  • toBePlusOrMinus(absoluteDelta:Number).from(value2:Number)
  • toContain(value2:Object)
  • toEndWith(value2:String) / toStartWith(value2:String)
  • toEqual(value2:Object)
  • toPatternMatch(value2:String, matches:Number=1)

they are defined in Matcher.ls; you can see them used in the specifications for spec-ls itself: ExpectationSpec

reporters

spec-ls ships with three reporters:

  • AnsiReporter - prints a compact summary to the console using ANSI color codes
  • ConsoleReporter - traces the complete results with a minimum of frill
  • JunitReporter - writes jUnit style xml summaries for CI systems like Jenkins and Bamboo

..or create your own by implementing the simple Reporter interface.

random seed

by default, Spec will execute tests in a different random order every time, to guard against accidental order dependencies.

to reproduce the order of a specific run, pass in the same seed value to Spec.execute():

        override public function run():void
        {
            MySpec.describe();

            Spec.addReporter(new ConsoleReporter());

            var seed:Number = 71387;
            Spec.execute(seed);
        }

building

first, install loomtasks

compiling from source

$ rake lib:install

this will build the Spec library and install it in the currently configured sdk

running tests

$ rake test

this will build the Spec library, install it in the currently configured sdk, build the test app, and run the test app.

contributing

Pull requests are welcome!