Internationalisation
Bundled Plugins API
Scenario
A Definition which describes a specific scenario.
A Scenario is most typically created via the it function, like so:
1
local spec = require "cp.spec"
2
local describe, it = spec.describe, spec.it
3
4
local Rainbow = require "my.rainbow"
5
6
return describe "a rainbow" {
7
it "has seven colors"
8
:doing(function()
9
local rainbow = Rainbow()
10
assert(#rainbow:colors() == 7, "the rainbow has seven colors")
11
end)
12
}
Copied!
Scenarios can be run asynchronously via the Run.This instance passed to the doing function. To indicate a scenario is asynchronous, call this:wait(), then call this:done(), to indicate it has completed. Any assert call which fails will result in the run failing, and stop at that point.
For example:
1
return describe "a rainbow" {
2
it "has a pot of gold at the end"
3
:doing(function(this)
4
this:wait()
5
local rainbow = Rainbow()
6
rainbow:goToEnd(function(whatIsThere)
7
assert(whatIsThere:isInstanceOf(PotOfGold))
8
this:done()
9
end)
10
end)
11
}
Copied!
Definitions can also be data-driven, via the where method:
1
return describe "a rainbow" {
2
it "has ${color} at index ${index}"
3
:doing(function(this)
4
local rainbow = Rainbow()
5
assert(rainbow[this.index] == this.color)
6
end)
7
:where {
8
{ "index", "color" },
9
{ 1, "red" },
10
{ 2, "orange" },
11
{ 3, "yellow" },
12
{ 4, "blue" },
13
{ 5, "green" },
14
{ 6, "indigo" },
15
{ 7, "violet" },
16
},
17
}
Copied!
This will do a run for each variation and interpolate the value into the run name for each.
Note: "where" parameters will not override built-in functions and fields in the this instance (such as "async" or "done") so ensure that you pick names that don't clash.

API Overview

  • Constructors - API calls which return an object, typically one that offers API methods
  • Scenario
  • Methods - API calls which can only be made on an object returned by a constructor
  • doing
  • run
  • where

API Documentation

Constructors

Scenario

Signature
cp.spec.Scenario(name[, testFn]) -> cp.spec.Scenario
Type
Constructor
Description
Creates a new Scenario with the specified name.
Parameters
  • name - The name of the scenario.
  • testFn - (optional) The function which performs the test for in the scenario.
Returns
  • The new Scenario.
Notes
  • If the testFn is not provided here, it must be done via the doing method prior to running, an error will occur.

Methods

doing

Signature
cp.spec.Scenario:doing(actionFn) -> self
Type
Method
Description
Specifies the function for the definition.
Parameters
  • testFn - The function that will do the test.
Returns
  • The same Definition.

run

Signature
cp.spec.Scenario:run(...) -> cp.spec.Run
Type
Method
Description
Runs the scenario.
Parameters
  • ... - The list of filters. The first one will be compared to this scenario to determine it should be run.

where

Signature
cp.spec.Scenario:where(data) -> cp.spec.Where
Type
Method
Description
Specifies a table of data that will be iterated through as multiple Runs, one row at a time.
Parameters
  • data - The data table.
Returns
Last modified 1mo ago