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

Rewrite one test to move away from Specta #319

Merged
merged 5 commits into from
Nov 14, 2022

Conversation

crazytonyli
Copy link
Contributor

Mainly because Specta doesn't support SPM. Also, it's no longer in active development.

The test case WPAnalyticsTests is also rewritten in Swift, so that we can continue use the Swift version of Quick when adding Swift Package Manager support later.

@crazytonyli crazytonyli requested a review from a team November 8, 2022 07:16
From Specta's GitHub repo:
> Specta is considered a done project [...], we recommend you consider Quick.
@crazytonyli crazytonyli force-pushed the move-from-specta-to-quick branch from b19dd50 to 5f6fa84 Compare November 9, 2022 21:28
Comment on lines +9 to +10
XCTFail("Test case needs to provide a context")
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: Once can also inline this, like return XCTFail(...).

It's probably not a good idea in this test suite because it's not a pattern it uses but I find it neat, specially under the hood. At first look it looks weird but thinking about it it's obviously okay. XCTFail returns Void so it's totally legit to "return it" because it's the same as return Void or return.

🤓

return
}

it("should not be called if tqracker isn't registered") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should not be called if tqracker isn't registered") {
it("should not be called if tracker isn't registered") {

Comment on lines +44 to +70
void WPAnalyticsTestVerifyUnregistered(WPAnalyticsMethodBehaviorInvocation invocation) {
id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]);
id expectation = [trackerMock reject];
invocation(expectation);
[trackerMock verify];
}

void WPAnalyticsTestVerifyRegistered(WPAnalyticsMethodBehaviorInvocation invocation) {
id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]);
id expectation = [trackerMock expect];
invocation(expectation);
invocation(trackerMock);
[trackerMock verify];
}

void WPAnalyticsTestVerifyMultipleTrackers(WPAnalyticsMethodBehaviorInvocation invocation) {
id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]);
id trackerMock2 = OCMStrictClassMock([TestAnalyticsTracker class]);
id expectation = [trackerMock expect];
id expectation2 = [trackerMock2 expect];
invocation(expectation);
invocation(expectation2);
invocation(trackerMock);
invocation(trackerMock2);
[trackerMock verify];
[trackerMock2 verify];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reason these have been defined in the Objective-C layer, although used only in the Swift / Quick code, that they use OCMock?

I noticed that OCMStrictClassMock is a macro and we could replace it with its definition like let trackerMock = OCMockObject.mock(for: TestAnalyticsTracker.self). But then things fall apart because OCMock relies on Objective-C's dynamism, but in Swift the type system gets in the way. I was not able to call verify() on my Swift trackerMock instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reason these have been defined in the Objective-C layer, although used only in the Swift / Quick code, that they use OCMock?
Yes. I'd like to keep the original tests, but I'm not familiar with OCMock, not sure if there is a way to move all these code into a Swift file.

Copy link
Contributor

@mokagio mokagio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one gnarly test to convert from Specta to Quick. Well done!

Do you plant to do the same for Expecta? As far as I can see, we still have it in the Podfile but no longer use it.

@crazytonyli
Copy link
Contributor Author

@mokagio Good catch! I just check Expecta is not used in this project and I've deleted it in bea05fa

@crazytonyli crazytonyli merged commit 346953e into trunk Nov 14, 2022
@crazytonyli crazytonyli deleted the move-from-specta-to-quick branch November 14, 2022 20: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.

2 participants