SPEC?

What the %$%^$ is SPEC?



Test Blocks

Test Blocks

The most basic unit in the SPEC tools is 'tests'. This function takes a name, and a codeblock to run.

Test blocks are not run immedietly, they will be run when the done_testing() function is called.

You can run a specific codeblock using the $T2_WORKFLOW variable, which takes either a name or a line number.

Params

Test Block Params

ParameterDefaultDescription
flat 0Do not render block as a subtest
todo undefMark entire block as TODO
skip undefDo not run the block, generate skip event
iso 0Isolate test by forking or spawning a new thread
async0Test can be run concurrently (but does not have to be)

You can combine any number of these at once.

Describe

Describe Blocks

Describe blocks are a way of grouping test blocks together along with any setup and teardown.
Before

Before

After

After

Around

Around

Cases

Test Cases

Output:
Case Mods

Case Modifiers

Order of execution:
  1. before_all
  2. (for each case)
    1. before_case
    2. case
    3. after_case
    4. (for each test block)
      1. before_each
      2. tests
      3. after_each
  3. after_all
Mocking

Mocking

Test2::Tools::Spec is smart with Test2::Tools::Mock. It treats a mock in void context as a before_each (roughly).

Declare

Declare

Test2::Plugin::SpecDeclare provides nice syntax sugar: