Skip to content

Commit

Permalink
Merge pull request #2 from dprotaso/master
Browse files Browse the repository at this point in the history
AfterEach should always be invoked if BeforeEach was successfully invoked
  • Loading branch information
Paul Warren authored Sep 9, 2016
2 parents b7218b7 + f0cd074 commit d45c473
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ public void run() throws Exception {
for (ExecutableBlock block : chain.getBeforeEachs()) {
block.invoke();
}

for (ExecutableBlock block : chain.getJustBeforeEachs()) {
block.invoke();
}

chain.getSpec().invoke();

for (ExecutableBlock block : chain.getAfterEachs()) {
block.invoke();
}
try {
for (ExecutableBlock block : chain.getJustBeforeEachs()) {
block.invoke();
}

chain.getSpec().invoke();
} finally {
for (ExecutableBlock block : chain.getAfterEachs()) {
block.invoke();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,39 @@ public class SpecRunnerThreadTests {

});

Context("when a JustBeforeEach throws an Exception", () -> {

BeforeEach(() ->{
setupOneBeforeOneAfterSpec();
justBefore = mock(ExecutableBlock.class);
chain.getJustBeforeEachs().add(justBefore);
doThrow(Exception.class).when(justBefore).invoke();
});

It("should call Before, JustBefore and After", () -> {
InOrder order = inOrder(/*notifier, */before, justBefore, after);
order.verify(before).invoke();
order.verify(justBefore).invoke();
order.verify(after).invoke();
verifyNoMoreInteractions(/*notifier, */before, justBefore, after);
});

});

Context("when an it throws an Exception", () -> {

BeforeEach(() ->{
setupOneBeforeOneAfterSpec();
doThrow(Exception.class).when(it).invoke();
});

It("should call before each but not the spec or afters", () -> {
It("it should still call AfterEach after the spec", () -> {
InOrder order = inOrder(/*notifier, */before, it, after);
order.verify(before).invoke();
order.verify(it).invoke();
order.verify(after).invoke();
verifyNoMoreInteractions(/*notifier, */before, it, after);
});

});


Expand Down

0 comments on commit d45c473

Please sign in to comment.