Skip to content

Testing Keywords

Keywords for test setup, assertions, and test variations.

Setup Keywords

given:

Declarative test setup. Describes the initial state.

Scenario-level:

flow
scenario: checkout

  given:
    @customer is logged in
    cart has items
    $total: number is 1200

Event-level:

flow
on :checkout from @customer (api)

  given:
    $discount_code is "SUMMER20"

  ? discount is valid
    apply discount

expect:

Defines assertions to verify outcomes.

Event-level:

flow
on :checkout from @customer (api)
  order moves to #processing

  expect:
    = order is in #processing

Scenario-level:

flow
scenario: complete purchase

  on :checkout from @customer (api) ...
  on :payment_success from @payment ...

  expect:
    = order is in #paid
    = @customer received :confirmation

Guard Keywords

otherwise

Default case when no guards match.

flow
? $total > 1000
  priority becomes "high"
? $total > 100
  priority becomes "medium"
otherwise
  priority becomes "low"

Equivalent to empty ?:

flow
? $total > 100
  apply discount
?
  no discount

Test File Keywords

test:

Defines a test file for a machine or system.

flow
test: @order
test: system checkout

for scenario:

Targets a specific scenario for testing.

flow
test: @order

  for scenario: checkout
    // tests for checkout scenario

for :event:

Targets transition tests for a specific event handler.

flow
for :checkout:
  empty cart rejected:
    with scenario:
      cart is empty
    = @customer received :error

for :event to @actor:

For system tests, targets an event to a specific machine.

flow
for :checkout to @order:
  guest rejected:
    // test variations

Variation Keywords

with scenario:

Overrides scenario-level given block.

flow
with scenario:
  cart is empty
  @customer is not logged in

with event:

Overrides event data/payload.

flow
with event:
  payment_method is "bank_transfer"

with given:

Overrides event-level given block.

flow
with given:
  shipping_address is invalid

with context:

Overrides context variables.

flow
with context:
  $total is 5000
  $retry_count is 2

Behavior Control Keywords

assume:

Controls guard/action behavior for the test.

flow
assume:
  ? cart is valid = false
  process payment throws "Error"
  send email returns { status: "sent" }

observe:

Watches actions without changing behavior.

flow
observe:
  send confirmation email
  update inventory

= send confirmation email was called
= update inventory was not called

Response Assertion Keywords

= reply status is

Verifies the HTTP status code of a reply.

flow
expect:
  = reply status is 201
  = reply status is 400

= reply.field

Verifies a field value in the response.

flow
expect:
  = reply.id is not empty
  = reply.status equals "awaiting_payment"
  = reply.customer.name equals "John"

= reply contains / does not contain

Checks for field presence in response.

flow
expect:
  = reply contains id
  = reply does not contain tracking

= callback for :event was sent

Verifies async callback delivery.

flow
expect:
  = callback for :generate_report was sent

Path Divergence Keywords

after

Specifies divergence point in scenario tests.

flow
payment fails:
  after :checkout
  receive :payment_failed
  = order is in #failed

receive

Specifies event received after divergence.

flow
after :checkout
receive :payment_failed from @payment

then

Continues event sequence after divergence.

flow
after :checkout
receive :payment_failed from @payment
then :payment_success from @payment
= order is in #paid

Released under the MIT License.