commonMain.io.mockk.impl.eval.EveryBlockEvaluator.kt Maven / Gradle / Ivy
package io.mockk.impl.eval
import io.mockk.CapturingSlot
import io.mockk.MockKGateway
import io.mockk.MockKGateway.CallRecorder
import io.mockk.MockKGateway.Stubber
import io.mockk.MockKMatcherScope
import io.mockk.MockKStubScope
import io.mockk.impl.recording.AutoHinter
class EveryBlockEvaluator(
callRecorder: () -> CallRecorder,
autoHinterFactory: () -> AutoHinter
) : RecordedBlockEvaluator(callRecorder, autoHinterFactory), Stubber {
@Suppress("UNCHECKED_CAST")
override fun every(
mockBlock: (MockKMatcherScope.() -> T)?,
coMockBlock: (suspend MockKMatcherScope.() -> T)?
): MockKStubScope {
if (coMockBlock != null) {
initializeCoroutines()
}
callRecorder().startStubbing()
val lambda = CapturingSlot>()
val scope = MockKMatcherScope(callRecorder(), lambda)
record(scope, mockBlock, coMockBlock)
val opportunity = callRecorder().answerOpportunity() as MockKGateway.AnswerOpportunity
return MockKStubScope(opportunity, callRecorder(), lambda)
}
}