--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/46177435-e16e-4c9a-a3e8-9bcd017a777c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The problem is that your tests are not written to be independent. It’s really, really important that each test is able to pass when run individually and also pass when all the specs are run, in any order. RSpec supports random ordering (--order random) to help surface cases where you’ve failed to do this. I recommend you use it.
In your specific case, a big part of the problem is that you’re creating and mutating the DB records directly in your context blocks. context blocks are not designed for this. They provide a way to group multiple examples, provide helper methods, perform common setup via a before hook, etc, but you don’t want to directly manipulate the objects you are testing in a context block — instead move that into a before hook or helper method. When RSpec runs, it loads your spec file and evaluates all your describe and context blocks but does not run the examples (the it blocks), the hooks, or any let declarations. Instead, it stores them for later use. After loading all the spec files, RSpec applies any filtering, ordering, etc to the examples, and then runs them. That means that in your case, this is what’s happening:
To avoid these problems, here’s what I suggest:
context blocks and into a before hook defined in those contexts. This ensures that the logic will run just before the examples execute that depend on them, regardless of what order the examples execute in.--order random to .rspec so that your specs run in random order. This will surface ordering dependencies to you so that you can quickly fix them at the time you create them, rather than having them sit dormant in your test suite only to cause problems later. Each time RSpec runs it will print the seed it used for that run’s randomization, and you can use --seed <seed> to reproduce the run.HTH,
Myron