Skip to content

Getting Started

Project layout

A Behave project keeps spec files in a specs/ directory at the project root. The behave runner picks up any file matching spec.raku (e.g. 001-basic-spec.raku, users-spec.raku, subdir/admin-spec.raku).

1
2
3
4
5
6
7
my-project/
├── lib/
│   └── MyApp.rakumod
└── specs/
    ├── basic-spec.raku
    └── users/
        └── auth-spec.raku

Your first spec

Every spec file starts with use BDD::Behave; and then declares one or more top-level describe blocks.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
use BDD::Behave;

describe 'arithmetic', {
  it 'adds integers', {
    expect(1 + 1).to.be(2);
  }

  it 'multiplies integers', {
    expect(3 * 4).to.be(12);
  }
}

Running specs

Run all specs found in specs/:

1
behave

Run a single spec file:

1
behave specs/basic-spec.raku

During local development of an app whose lib/ is not yet installed, prefix with raku -Ilib:

1
raku -Ilib bin/behave specs/basic-spec.raku

See Running Specs for the full set of options.

Where to go next

  • describe / context — group related examples
  • it — define an example
  • let — lazy, memoized values per example
  • Hooksbefore-each, after-each, before-all, after-all
  • Shared Contexts — reusable lets and hooks via shared-context / include-context
  • expect — assertions