Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to verify initializer since 0.18.0 #240

Closed
2 tasks done
myihsan opened this issue Nov 18, 2021 · 5 comments · Fixed by #280
Closed
2 tasks done

Unable to verify initializer since 0.18.0 #240

myihsan opened this issue Nov 18, 2021 · 5 comments · Fixed by #280
Assignees
Labels
enhancement Feature request or improvement

Comments

@myihsan
Copy link
Contributor

myihsan commented Nov 18, 2021

New Issue Checklist

Description

I depend on the implementation below in a special case.

https://github.com/birdrides/mockingbird/blob/13ee8ab4346bf65c51612305a897dffcfab45e5c/Sources/MockingbirdGenerator/Generator/Templates/InitializerMethodTemplate.swift#L76-L82

But it has been deleted by #217.

Do we have to delete it for supporting partial mocks, or it's deleted unintentionally?

@andrewchang-bird
Copy link
Contributor

Can you provide an example of how you’re using this initializer in tests? It should still be generating this initializer variant (or at least that was the intention):

https://github.com/birdrides/mockingbird/blob/6a682afc667313cc2609d10ca871b819c02105f9/Sources/MockingbirdGenerator/Generator/Templates/InitializerMethodTemplate.swift#L58-68

@myihsan
Copy link
Contributor Author

myihsan commented Jan 11, 2022

Sorry for the late reply.
I am testing something like below.

protocol SomeProtocol: RawRepresentable {
    // some requirements
}

class SomeTest: XCTestCase {
    func testCreation() {
        let object = SomeCreator<SomeProtocolMock<Int>>.create()
        verifyRawValueInitCalled(on: object, with: -1)
    }

    private func verifyRawValueInitCalled<RawValue: Equatable>(on object: SomeProtocolMock<RawValue>, with rawValue: RawValue) {
        let invocation: Invocation = Invocation(selectorName: "init?(`rawValue`: RawValue) ", arguments: [ArgumentMatcher(rawValue)], returnType: Swift.ObjectIdentifier((Void).self))
        let declaration = Mockingbird.Mockable<Mockingbird.PropertyGetterDeclaration, () -> SomeProtocolMock<RawValue>, SomeProtocolMock<RawValue>>(mock: object, invocation: invocation)
        verify(declaration).wasCalled()
    }
}

It works before 0.18.0, but I only get an empty initializer since 0.18.0.

@andrewchang-bird
Copy link
Contributor

andrewchang-bird commented Jan 11, 2022

Got it, thanks for the code snippet.

I removed the initializer invocation recording in 0.18 as there isn’t an official way of calling verify on those declarations (you’re essentially using internal APIs here). I can see some value in asserting how objects are initialized, although it definitely is uncommon.

I’ll have to think a bit about how to design the API for this—it’ll probably end up using a synthetic declaration on the instance similar to the legacy property getters and setters. I can’t guarantee I can prioritize it for the next release though. If you’re interested in adding the feature (should be a medium-sized task) let me know and I can walk you through it.

verify(myMock.init(some: arg)).wasCalled()

@andrewchang-bird andrewchang-bird added the enhancement Feature request or improvement label Jan 11, 2022
@myihsan
Copy link
Contributor Author

myihsan commented Jan 13, 2022

although it definitely is uncommon.

I totally agree with you.

If you’re interested in adding the feature (should be a medium-sized task) let me know and I can walk you through it.

I would love to, but I may be active only at weekends and using some time to catch up on the latest implementations.
Do you think that's okay?

@andrewchang-bird
Copy link
Contributor

I would love to, but I may be active only at weekends and using some time to catch up on the latest implementations. Do you think that's okay?

Yes, for sure! We’re happy with whatever you’re comfortable contributing. Note that we currently use Slack for coordinating, but let me know if another option works better for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants