Skip to content

Conversation

@younata
Copy link
Member

@younata younata commented Dec 23, 2024

Resolves #7

Adds a new property wrapper for spying on and faking properties.

This is meant to be used like:

struct SomeType {
    @PropertySpy(2)
    var intValue: Int

    @PropertySpy(ConcreteImplementationOfSomeProtocol(), as: { $0 })
    var protocolValue: SomeProtocol
}

And then read like:

let instance = SomeType()
instance.$intValue // Spy<Void, Int>
instance.$protocolValue // Spy<Void, ConcreteImplementationOfSomeProtocol>

There is also a SettablePropertySpy, which works similarly, though the projectedValue (the $intValue or $protocolValue in the previous example) is a struct containing a getter and setter properties, which are spies recording calls to the property's get and set closures.

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?

@younata younata merged commit 9eb0edc into main Dec 23, 2024
7 of 8 checks passed
@younata younata deleted the property_spy branch December 23, 2024 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Faking out properties is a bit of a handful.

1 participant