4 ms·
This reminds me a lot of "context blocks" as implemented in the Ruby testing libraries Shoulda and RSpec (and probably elsewhere). A context is a named code blo
by samstokes 16y ago
This reminds me a lot of "context blocks" as implemented in the Ruby testing libraries Shoulda and RSpec (and probably elsewhere). A context is a named code block which can contain a number of tests, along with some common setup and teardown that's run for each test. Contexts can contain contexts, and tests in nested contexts get all the setup and teardown from their own context and its parent contexts, in the order you'd expect.
I've used nested contexts to achieve much the same sort of thing as Evan talks about here: high-coverage functional testing of a sequence of actions. They have the same advantage that the length of the test stays linear with the number of actions, although unlike Evan's callback-style tests, they didn't stop the test tree as soon as a step failed.