uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
813 stars 86 forks source link

[Combine] can set default value to `CurrentValueSubject` #234

Closed fummicc1 closed 1 year ago

fummicc1 commented 1 year ago

Overview

I added new metadata to set an explicit default value for CurrentValueSubject in a Mock object, which is used to manage the Publisher stream.

Problem

Currently, if publish type ( type A of Publisher<A, B>) is not kind of primitive type, subject becomes PassthroughSubject even if you mark it as CurrentValueSubject by @mockable(combine: aPublisher = CurrentValueSubject).

Note

This PR only addresses Combine, but RxSwift also has the same problem. I believe this should be considered a separate issue because the implementation differs from the Combine one.

Example

Screenshot 2023-05-03 at 23 49 51
fummicc1 commented 1 year ago

@sidepelican

I'm in no hurry but could you review this PR when you have time :pray:

sidepelican commented 1 year ago

This change looks good, but I don't want to expand the Combine related functions. In case of #175, it can also be avoided by using the --disable-combine-default-values option. This change doesn't seem necessary.

If we are going to be hospitable to #175, I think it would be to display warning messages when the CurrentValueSubject fall through implicitly to the PassthroughSubject. On that time, it would also be good to display the existence of the --disable-combine-default-values option.

fummicc1 commented 1 year ago

Yes. honestly, I did not know that flag. It is what I would like! Thank you.

it would be to display warning messages when the CurrentValueSubject fall through implicitly to the PassthroughSubject.

I will try to address to show the warning message instead of this PR. 👍

fummicc1 commented 1 year ago

close because other solution already exists.