What did you do?
I am writing a test helper to help me find memory leaks.
extension QuickSpec {
func trackForMemoryLeaks(
sut: AnyObject,
file: String = #filePath,
line: UInt = #line
) {
afterEach { [weak sut] in
expect(file: file, line: line, sut).to(beNil())
}
}
}
When I initialise my SUT I have a method like so:
extension MyTestSuite {
func makeSUT(
file: String = #filePath,
line: UInt = #line
) -> MySUT {
let sut = MySUT()
trackForMemoryLeaks(sut, file: file, line: line)
return sut
}
}
The problem is that in our company we have the convention of creating the SUT inside the it block. So when doing so I get the error 'afterEach' cannot be used inside 'it', 'afterEach' may only be used inside 'context' or 'describe'.
I tried to replace the afterEach with addTeardownBlock but in that case the teardown block is never called. Is there any way to add support for afterEach to be run inside the it block, or add support for addTeardownBlock to be called after each it statement finishes?
Further, if I move my makeSUT call inside a describe or context scope, the SUT is never deallocated because it's held in memory by that describe or context scope, so I can't test properly that it's being deallocated.
So I assume the solution to this is to add support for addTeardownBlock inside an it statement.
What did you expect to happen?
addTeardownBlock should be called after the it statement.
What actually happened instead?
addTeardownBlock was never called, regardless where of the scope it was declared in (it, describe or context)
Environment
List the software versions you're using:
- Quick: 5.0.1
- Nimble: 10.0.0
- Xcode Version: 14.3.1
- Swift Version:
Xcode Default
Please also mention which package manager you used and its version. Delete the
other package managers in this list:
What did you do?
I am writing a test helper to help me find memory leaks.
When I initialise my SUT I have a method like so:
The problem is that in our company we have the convention of creating the SUT inside the
itblock. So when doing so I get the error'afterEach' cannot be used inside 'it', 'afterEach' may only be used inside 'context' or 'describe'.I tried to replace the
afterEachwithaddTeardownBlockbut in that case the teardown block is never called. Is there any way to add support forafterEachto be run inside theitblock, or add support foraddTeardownBlockto be called after eachitstatement finishes?Further, if I move my
makeSUTcall inside adescribeorcontextscope, the SUT is never deallocated because it's held in memory by thatdescribeorcontextscope, so I can't test properly that it's being deallocated.So I assume the solution to this is to add support for
addTeardownBlockinside anitstatement.What did you expect to happen?
addTeardownBlockshould be called after theitstatement.What actually happened instead?
addTeardownBlockwas never called, regardless where of the scope it was declared in (it,describeorcontext)Environment
List the software versions you're using:
Xcode DefaultPlease also mention which package manager you used and its version. Delete the
other package managers in this list: