I understand what's happening. Code inside a describe block is executed at the time the specs are defined, not run; after all, the example definitions themselves are simply executable code. This means that any code executed in a describe block will run once, and only once. This can be helpful for setting up immutable state, but keep in mind it can lead to test pollution since the setup is not refreshed for each example.
As far as running a setup for a specific file, unfortunately there's no way to do that. Cedar has no concept of files, only of examples and example groups. From an implementation point of view, Cedar instantiates each spec class (delineated by SPEC_BEGIN and SPEC_END) at runtime and executes the example definition code; it doesn't actually execute any examples until after all example definition code has been run. This is because examples in file A can depend on shared example groups in file B, or on beforeEach blocks later in the same file.
If your setup time is long enough that using a beforeEach is impractical, then you could set up separate spec targets for each long-running setup. This is a bit inconvenient for running everything, but it should be a simple task to write a rake task or bash script to run them all in sequence.
On Thu, Nov 22, 2012 at 6:28 PM,
<adam....@ennova.com.au> wrote:
Currently I just have the code inside a describe block, I'm trying to avoid a beforeEach() block as the setup is relatively slow but maybe thats what I have to do. The problem occurs when setup code from file B is run before specs in file A.
Is there a way I can create a file context type thing or run each separate spec file in isolation so that setup code in file A is run, then specs in file A, followed by the setup in file B and the specs in file B?