Say I have a Field
class with a harvest
function like this:
class Field {
func harvest(handler: (Vegetable) -> Void) {
…
handler(carrot)
…
handler(potato)
…
handler(carrot)
…
}
}
I also have a Reactive version/API for the same function:
import RxSwift
extension Reactive where Base: Field {
func harvest() -> Observable<Vegetable> {
return Observable.create { observer in
self.base.harvest(handler: observer.onNext)
return Disposables.create()
}
}
}
For testing purposes, I created a subclass of Field
named MockField
that overrides harvest(:)
to invoke the handler with a set of stubbed Vegetable
s. When using the MockField
object like field.harvest(:)
everything works fine and I get the stubbed vegetables.
Now I want to do the same with the Reactive extension to stub calls to field.rx.harvest
, but I cannot override it to return stubbed Vegetables! How can I override functions in the rx
namespace?