Closed snobb closed 6 years ago
According to the ginkgo documentation justBeforeEach
solved some BDD anti pattern which is related to code reuse. I've been looking at other popular BDD libraries like mocha and jasmine and none have implemented and discussed this pattern. Even though I agree that it helps to reduce code duplication, I believe it also adds some complexity in understanding the way things run during tests. I'm not entirely convinced to merge this due to this last comment.
Is there any other strong argument to include this @snobb which I might be missing?. Don't get me wrong, I do believe it's useful it's just that I just don't want to add stuff just because some other framework has it.
We've been using ginkgo and currently want to move to goblin mostly because it's smaller/simpler and has no dependencies. Our tests heavily relied on the JustBeforeEach though and thus converting our tests means we have to introduce helper lambda funcs everywhere it's been used (or just hard code the same code over and over). Given the ease of adding this functionality I thought it would be nice to just have it. There is no obligation to use it nor it brakes any existing tests - just more granularity at a cost of a little change. I am also a heavy user of mocha and think mocha could also benefit from this (IMHO). It's much easier to get around the lack of this feature in nodejs though. :)
Fair enough. Let's merge this
Thanks a lot!
JustBeforeEach allows you to decouple creation from intialization. Initalization occurs in the JustBeforeEach using configuration specified and modified by a chain of BeforeEachs. This allows for a better code reuse in tests.
JustBeforeEach fires after BeforeEach but before It for each It in the block. Similar to BeforeEach blocks JustBeforeEach from outer blocks has presedence over the local JustBeforeEach.
For more info: https://onsi.github.io/ginkgo/#separating-creation-and-configuration-justbeforeeach
The JustBeforeEach clause allows for doing this: