Add support for `NSObjectProtocol` in ObjC mocking.

This commit is contained in:
Matyáš Kříž 2020-07-31 08:29:14 +02:00
parent 1d31d53b04
commit 5bb308952e
2 changed files with 35 additions and 0 deletions

View File

@ -68,6 +68,18 @@ public extension StubRecorder where OUT: NSObject {
}
}
public extension StubRecorder where OUT: NSObjectProtocol {
func thenReturn(_ object: OUT) {
recorder.andReturn(object)
}
}
public extension StubRecorder where OUT == Optional<NSObjectProtocol> {
func thenReturn(_ object: OUT) {
recorder.andReturn(object)
}
}
public extension StubRecorder where OUT: CuckooOptionalType, OUT.Wrapped: NSObject {
func thenReturn(_ object: OUT) {
recorder.andReturn(object)

View File

@ -0,0 +1,23 @@
//
// ObjectiveExamplesTest.swift
// Cuckoo_OCMock-iOSTests
//
// Created by Matyáš Kříž on 31/07/2020.
//
import XCTest
import Cuckoo
import CoreBluetooth
class ObjectiveExamplesTest: XCTestCase {
func testProperties() {
let mock = objcStub(for: CBCentralManager.self) { stubber, mock in
stubber.when(mock.delegate).thenReturn(nil)
}
let g = mock.delegate
objcVerify(mock.delegate)
}
}