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 is not executed when NSException is thrown #822

Open
1 task done
tomquist opened this issue Sep 28, 2018 · 2 comments
Open
1 task done

afterEach is not executed when NSException is thrown #822

tomquist opened this issue Sep 28, 2018 · 2 comments

Comments

@tomquist
Copy link

tomquist commented Sep 28, 2018

  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

We currently have a very large test suite (several thousands of Specs) that uses Cedar which is not really maintained anymore. Due to the very similar API we try to migrate all specs from Cedar to Quick but would like to still use the Doubles and Matchers of Cedar. Unfortunately the Cedar Matchers throw NSExceptions instead of letting the current test case fail. This is not a big problem since Quick continues to execute examples. However, as soon as a test fails due to an exception no afterEach block of the corresponding example is executed. This sometimes leads to a situation where following tests are executed in an unclean state so that they fail even though they would have been successful when the previous test didn't throw an exception. This often happens when we spy a class using start_spying_on([Some class]) that has to be unspied in afterEach.

What did you expect to happen?

afterEach blocks are still executed when an example fails due to an exception.

What actually happened instead?

No afterEach block is executed.

Environment

List the software versions you're using:

  • Quick: 1.3.1
  • Nimble: 7.1.3
  • Xcode Version: 9.4.1 (9F2000)
  • Swift Version: Xcode Default
  • Carthage: 0.30.1

Project that demonstrates the issue

Download zip file here

@ikesyo
Copy link
Member

ikesyo commented Jun 11, 2019

I assume this will be a bug.

@andredsp
Copy link

I've made a few tests using a variation of the ObjC class from this StackOverflow discussion where I could handle NSException like a swift Error, so the afterEach blocks were still executed.

I can prepare a PR with this but one thing comes to my mind. If NSException is treated as a usual try/catch block, wouldn't we be in a false sense of security for having the afterEach blocks being executed, but the system would actually be in a non-deterministic error state? Should we just abort the whole error suite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants