Scope of after_each
Opened this issue · 1 comments
I'm facing unexpected behavior with after_each when there are multiple contexts. It appears the after_each is running for the tests in the wrong context.
The following example demonstrates the issue.
#include "bdd-for-c.h"
spec("after-each") {
context("Context 1") {
after_each() {
check(0);
}
it("should fail") {
}
}
context("Context 2") {
it("should succeed") {
check(1);
}
}
}
Output:
after-each
Context 1
should fail (OK)
Context 2
should succeed (FAIL)
Check failed: 0
at ../test_after_each.c:6
2 tests run, 1 failed.
I expected the after_each() in Context 1 to fail the tests in Context 1. Instead, it fails the test in Context 2.
This is indeed an undesirable behavior and I believe it is a part of a larger problem. I haven't worked on this project deeply in a bit but if I remember correctly the code does not support check
calls in before
/ after
statements at all.
I can not promise that I would have time to work on this any time soon but would be happy to accept a PR that would add this functionality if you or anyone else would like to add it.