-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
From Specta's GitHub repo: > Specta is considered a done project [...], we recommend you consider Quick.
b19dd50
to
5f6fa84
Compare
XCTFail("Test case needs to provide a context") | ||
return |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("should not be called if tqracker isn't registered") { | |
it("should not be called if tracker isn't registered") { |
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]; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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.