This is much different from the nested sections in (for example) telescope... in those frameworks, the tests themselves cannot be nested (only the "context"), and the nested sections do not run in isolation.
Here's an example:
Code: Select all
T('Given a value of two', function (T)
local value = 2
T('When the value is increased by five', function (T)
-- here, value is 2
value = value + 5
T:assert(value == 7, 'Then the value equals seven')
end)
T('When the value is decreased by five', function (T)
-- value is 2 again; this test is isolated from the "increased by five" test
value = value - 5
T:assert(value == -3, 'Then the value equals negative three')
end)
end)
- Given a value of two
When the value is increased by five
Then the value equals seven
- Given a value of two
When the value is decreased by five
Then the value equals negative three