Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AfterEach should always be invoked if BeforeEach was successfully invoked #2

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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