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
[XCTestExpectation] Adding expectationForNotification #85
Conversation
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:125: error: ExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect notification 'notificationWithIncorrectObjectTest' from dummyObject | ||
// CHECK: Test Case 'ExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails' failed \(\d+\.\d+ seconds\). | ||
func test_observeNotificationWithIncorrectObject_fails() { | ||
let notificationNamme = "notificationWithIncorrectObjectTest" |
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.
“notificationName”
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.
🚗 💨
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.
😂 You got me
🙏 Namaste
This is awesome, thanks @yoonapps!! 💯 I have a few nitpicks, but other than those this looks great to me! |
objectDescription = "\(object)" | ||
} else { | ||
objectDescription = "any object" | ||
} |
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.
nit-pick: Perhaps use a ternary operator here?
let objectDescription = object == nil ? "any object" : "\(object)"
I don't have a strong opinion either way, but a ternary operator would only take one line, whereas this approach uses six.
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.
I was thinking about the ternary operator but if I don't unwrap the optional, then the object description comes with Optional(description)
. This led to using the if statement. I can change it to the ternary operator as long as it's cool to do "\(object!)"
(force unwrap).
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.
Or is it better to print in the description that the argument is an optional? Maybe it's something to consider since the description is following the Obj C style.
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.
Oh, good point! Perhaps this, then?
let objectDescription = object == nil ? "any object" : "\(object!)"
Or we could leave this as-is. Again, I don't have a strong opinion here. :)
@yoonapps This is fantastic! 😍 Could you squash these three commits into one? @mike-ferris-apple Could you ask @swift-ci to please test? |
Awesome, yes I will address these reviews and squash the commits this evening! Thanks for the reviews. |
/// allows a nil notification name for its criteria of observing | ||
/// notifications, the Objective-C implementation of this function | ||
/// requires a notification name. | ||
public func expectationForNotification(notificationName: String, object: AnyObject?, handler: XCNotificationExpectationHandler?) -> XCTestExpectation { |
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.
Super minor nit-pick: Technically the Apple XCTest signature for this method is:
public func expectationForNotification(notificationName: String, object objectToObserve: AnyObject?, handler: XCNotificationExpectationHandler?) -> XCTestExpectation
I don't think the parameter name is important, but I'd personally prefer to be 100% consistent. 😛
@swift-ci please test |
c70c5f4
to
adae1b2
Compare
@modocache addressed issues |
XCTMain([testCase(NotificationExpectationsTestCase.allTests)]) | ||
|
||
// CHECK: Executed 5 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds | ||
// CHECK: Total executed 5 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds |
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.
nit-pick: Add a new line at the end of this file so Git won't complain 😛
@modocache |
Ok well Github is not showing the extra line... but there is one 😕 |
Yup, it's there! If no new line is present at the bottom of a file GitHub shows a symbol that looks like 🚫. Sorry @mike-ferris-apple, but could you ask @swift-ci to please test again? I think the updates to the pull request cancelled the previous CI job. If CI passes on Linux (OS X is still broken, see #77), then I'll merge. 😄 |
@swift-ci please test |
😖
|
@yoonapps Nice catch!! It most certainly is a file path issue, one I've seen before--it's pretty nasty, but we need to use a unique file name for each test. You should be fine if you "namespace" your test file name, like so:
Sorry about that. I'll create a JIRA issue so we can track fixing this. |
@modocache Ok! I updated the paths for both the Notification Expectations and Handler |
@mike-ferris-apple Mind asking @swift-ci to please test again? 😅 I wonder when CI will be opened up to all committers... 💭 |
Sorry! |
Haha, don't be! I'm actually fine with merging this without testing again, but better safe than sorry. |
- Prints the same description as Obj C - Uses the default notification center to observe for notifications - Optional handler returns true or false of whether the expectation was fulfilled - Tests check comparing the notification and object arguments for the expectation and notification - Tests check returning true or false in handler
@swift-ci please test |
Awesome, thanks @yoonapps! Congratulations on completing your first starter task! 💐 |
AWWWW YEEEEE |
What's in this pull request?
This pull request adds the XCTestCase convenience constructor for XCTestExpectation
expectationForNotification:object:handler:
.It also includes the
XCNotificationExpectationHandler
typealias
file as well as tests to checkexpectationForNotification:object:handler:
behavior.https://bugs.swift.org/browse/SR-907
However, this pull request does not include the convenience constructor
expectationForPredicate:evaluatedWithObject:handler:
described in the ticket, asNSPredicate
initializers have yet to be implemented.Why merge this pull request?
This will provide a full Swift implementation of
expectationForNotification:object:handler:
that allows asynchronous testing forNSNotification
.