Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Sources/Nimble/Matchers/PostNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ internal class NotificationCollector {

private let mainThread = pthread_self()

private func _postNotifications(
private func _postNotifications<Out>(
_ predicate: Predicate<[Notification]>,
from center: NotificationCenter,
names: Set<Notification.Name> = []
) -> Predicate<Any> {
) -> Predicate<Out> {
_ = mainThread // Force lazy-loading of this value
let collector = NotificationCollector(notificationCenter: center, names: names)
collector.startObserving()
Expand Down Expand Up @@ -80,27 +80,27 @@ private func _postNotifications(
}
}

public func postNotifications(
public func postNotifications<Out>(
_ predicate: Predicate<[Notification]>,
from center: NotificationCenter = .default
) -> Predicate<Any> {
) -> Predicate<Out> {
_postNotifications(predicate, from: center)
}

@available(*, deprecated, renamed: "postNotifications(_:from:)")
public func postNotifications(
public func postNotifications<Out>(
_ predicate: Predicate<[Notification]>,
fromNotificationCenter center: NotificationCenter
) -> Predicate<Any> {
) -> Predicate<Out> {
postNotifications(predicate, from: center)
}

#if os(macOS)
public func postDistributedNotifications(
public func postDistributedNotifications<Out>(
_ predicate: Predicate<[Notification]>,
from center: DistributedNotificationCenter = .default(),
names: Set<Notification.Name>
) -> Predicate<Any> {
) -> Predicate<Out> {
_postNotifications(predicate, from: center, names: names)
}
#endif
Expand Down
8 changes: 1 addition & 7 deletions Tests/NimbleTests/Matchers/PostNotificationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ final class PostNotificationTest: XCTestCase {
func testPassesWhenNoNotificationsArePosted() {
expect {
// no notifications here!
return nil
}.to(postNotifications(beEmpty()))
}

Expand All @@ -24,10 +23,9 @@ final class PostNotificationTest: XCTestCase {
let bar = 2 as NSNumber
let n1 = Notification(name: Notification.Name("Foo"), object: foo)
let n2 = Notification(name: Notification.Name("Bar"), object: bar)
expect {
expect { () -> Void in
self.notificationCenter.post(n1)
self.notificationCenter.post(n2)
return nil
}.to(postNotifications(equal([n1, n2]), from: notificationCenter))
}

Expand All @@ -36,7 +34,6 @@ final class PostNotificationTest: XCTestCase {
failsWithErrorMessage("expected to equal <[\(testNotification)]>, got no notifications") {
expect {
// no notifications here!
return nil
}.to(postNotifications(equal([testNotification]), from: self.notificationCenter))
}
}
Expand All @@ -47,7 +44,6 @@ final class PostNotificationTest: XCTestCase {
failsWithErrorMessage("expected to equal <[\(n1)]>, got <[\(n2)]>") {
expect {
self.notificationCenter.post(n2)
return nil
}.to(postNotifications(equal([n1]), from: self.notificationCenter))
}
}
Expand All @@ -58,7 +54,6 @@ final class PostNotificationTest: XCTestCase {
failsWithErrorMessage("expected to equal <[\(n1)]>, got <[\(n2)]>") {
expect {
self.notificationCenter.post(n2)
return nil
}.to(postNotifications(equal([n1]), from: self.notificationCenter))
}
}
Expand All @@ -69,7 +64,6 @@ final class PostNotificationTest: XCTestCase {
deferToMainQueue {
self.notificationCenter.post(testNotification)
}
return nil
}.toEventually(postNotifications(equal([testNotification]), from: notificationCenter))
}

Expand Down