Polidea / RxBluetoothKit

iOS & OSX Bluetooth library for RxSwift
Apache License 2.0
1.41k stars 366 forks source link

Mock ScannedPeripheral #350

Open Raphzz opened 5 years ago

Raphzz commented 5 years ago

Hi! We are implementing Bluetooth scanning in our App, it's my first time using RxBluetoothKit and I am loving it!

I am having trouble writing my tests for our Bluetooth service:

protocol BluetoothScanServiceProtocol {
    func startScanForBluetoothDevices(with service: String) -> Observable<ScannedPeripheral>
    func stopScanningBluetoothDevices()
}

How can I mock the ScannedPeripheral class? I won't have a real ScannedPeripheral on my tests of course

My mock class:

final class MockBluetoothService: BluetoothScanServiceProtocol {
    func startScanForBluetoothDevices(with service: String) -> Observable<ScannedPeripheral> {
        return Observable.just(ScannedPeripheral()) // I can't initialize ScannedPeripheral 
    }

    func stopScanningBluetoothDevices() {}
}