Skip to content

2. Expectations

Chesko edited this page May 15, 2016 · 20 revisions

Expectations are the building blocks of your test cases. If all expectations are true in a test case, the spec passes. If an expectation is not true, the spec fails.

Expectations are built with one of the included expect functions. It has 4 parameters: the actual, a condition, a matcher, and the expected. They are read in the form of "expect actual to / not to match expected". In the below example, we "expect 5 to be less than 7."

expectInt(5, to, beLessThan, 7)

Actual

An actual is the value under test, and is the first parameter in an expectation.

Condition

There are two conditions: to and notTo. notTo inverses the result of the matcher (we expect the actual "not to" be something).

; This expectation would pass
expectBool(True, to, beEqualTo, True)

; This expectation would fail
expectBool(True, notTo, beEqualTo, True)

Matcher

Each matcher implements a boolean comparison between the actual value and the expected value. It is responsible for determining if the expectation is true or false. Lilac will then pass or fail the spec.

Any matcher can evaluate to a negative assertion by using the notTo condition before the matcher.

Examples of matchers include beEqualTo, beGreaterThan, and contain.

Expected

An expected is the last parameter of an expectation, and is the value you expect the actual to be.

int n = 15
expectInt(n, to, beEqualTo, 15)

Some expectations don't require an expected, as they are built into the matcher. beTruthy, beFalsy, and beNone are such matchers.

expectBool(True, to, beTruthy)
expectBool(False, to, beFalsy)
expectForm(None, to, beNone)

Clone this wiki locally