You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, settable properties are just a terrible user experience. As of this issue, the only options are to either have the fake update spy's stub, or create 2 spies for the single property.
Either one is not great. Spy.stub(_:) is only supposed to be called in a test, not in the implementation of a Fake. However, re-stubbing the spy in the fake does make the Fake behave a little more "real" - I would expect SomeRandomValue.property to return the same value I just set, which this single-spy approach does handle nicely. Furthermore, the double-spy approach is just an unwieldy mouthful, even if it is more able to catch assignments.
So, I think a PropertySpy would be an excellent thing to create, which essentially is 2 spies, for tracking reads as well as writes, with calls to the write updating the stub of the read (and an option to disable that behavior).
Additionally, setting all this up is a lot of boilerplate that you shouldn't have to engage in. Thankfully, swift offers ways around this, such as property wrappers and attached macros. Either one should work, with property wrappers being significantly easier to maintain.
The text was updated successfully, but these errors were encountered:
If you try to apply a spy to a property, you're gonna have a bad time.
Read-only properties are at least not terrible, because they behave like standard functions.
However, settable properties are just a terrible user experience. As of this issue, the only options are to either have the fake update spy's stub, or create 2 spies for the single property.
Either one is not great.
Spy.stub(_:)
is only supposed to be called in a test, not in the implementation of a Fake. However, re-stubbing the spy in the fake does make the Fake behave a little more "real" - I would expectSomeRandomValue.property
to return the same value I just set, which this single-spy approach does handle nicely. Furthermore, the double-spy approach is just an unwieldy mouthful, even if it is more able to catch assignments.So, I think a
PropertySpy
would be an excellent thing to create, which essentially is 2 spies, for tracking reads as well as writes, with calls to the write updating the stub of the read (and an option to disable that behavior).Additionally, setting all this up is a lot of boilerplate that you shouldn't have to engage in. Thankfully, swift offers ways around this, such as property wrappers and attached macros. Either one should work, with property wrappers being significantly easier to maintain.
The text was updated successfully, but these errors were encountered: