ESC
Type to search...
S
Soli Docs

Testing Functions

Test DSL with describe/it blocks, assertions, and factory functions.

Test DSL

describe(description, def)

Define a test group. context is an alias.

test(description, def)

Define an individual test case.

it(description, def)

Alternative to test(). specify is an alias.

Example

describe("Calculator", def() {
    test("adds numbers", def() {
        assert_eq(add(1, 2), 3)
    })

    it("subtracts numbers", def() {
        assert_eq(subtract(5, 3), 2)
    })

    describe("division", def() {
        it("divides numbers", def() {
            assert_eq(divide(10, 2), 5)
        })

        it("handles division by zero", def() {
            # Test error handling
        })
    })
})

Setup & Teardown

before_each(def)

Run before each test

after_each(def)

Run after each test

before_all(def)

Run once before all tests

after_all(def)

Run once after all tests

pending()

Mark test as pending (not yet implemented)

skip()

Skip the current test

Assertions

assert_equal(expected, actual, message)

Asserts that two values are equal.

assert_equal(42, result, "should return 42");
assert_equal("hello", str, "string should match");
assert_equal(true, is_valid, "should be valid");
assert_true(value, message)

Asserts that a value is true.

assert_true(user.is_active, "user should be active");
assert_true(contains(items, "test"), "should contain test item");
assert_false(value, message)

Asserts that a value is false.

assert_false(user.is_blocked, "user should not be blocked");
assert_false(is_empty(items), "items should not be empty");
assert_contains(haystack, needle, message)

Asserts that a collection contains a specific value.

assert_contains(users, "admin", "should contain admin user");
assert_contains([1, 2, 3], 2, "should contain 2");
assert_nil(value, message)

Asserts that a value is nil (null).

assert_nil(result.error, "should have no error");
assert_nil(user.deleted_at, "should not be deleted");
assert_not_nil(value, message)

Asserts that a value is not nil.

assert_not_nil(user.id, "user should have an id");
assert_not_nil(response.body, "response should have body");

Assertion Result

All assertion functions return a result hash with the following structure:

{
    "passed": true,
    "message": "description of the test",
    "expected": value_that_was_expected,
    "actual": value_that_was_actual
}
assert_not(condition)

Assert condition is false

assert_eq(a, b)

Assert a equals b

assert_ne(a, b)

Assert a does not equal b

Null & Comparison

assert_null(value)

Assert value is null

assert_not_null(value)

Assert value is not null

assert_gt(a, b)

Assert a > b

assert_lt(a, b)

Assert a < b

Advanced Assertions

assert_match(str, pattern)

Assert string matches regex

assert_contains(coll, val)

Assert collection contains value

assert_hash_has_key(h, k)

Assert hash has key

assert_json(string)

Assert string is valid JSON

Factory Functions

Factory.define(name, data)

Define a factory with default data.

Factory.define("user", {
    "name": "Test User",
    "email": "[email protected]",
    "age": 25
})
Factory.create(name)

Create an instance from a factory.

let user = Factory.create("user")
println(user["name"])  # "Test User"
Factory.create_with(name, overrides)

Create an instance with custom overrides.

let admin = Factory.create_with("user", { "role": "admin" })
println(admin["role"])  # "admin"
println(admin["name"])  # "Test User" (from factory)
Factory.create_list(name, count)

Create multiple instances

Factory.sequence(name)

Get auto-incrementing number

Factory.clear()

Clear all factories