Skip to content

Commit 8f57007

Browse files
authored
Merge pull request #789 from Quick/8.x-rename-postNotifications
[8.x] Rename `postNotifications(_:fromNotificationCenter:)` to `postNotifications(_:from:)`
2 parents d117c12 + 8ef6d12 commit 8f57007

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ expect {
11861186
let notificationCenter = NotificationCenter()
11871187
expect {
11881188
notificationCenter.postNotification(testNotification)
1189-
}.to(postNotifications(equal([testNotification]), fromNotificationCenter: notificationCenter))
1189+
}.to(postNotifications(equal([testNotification]), from: notificationCenter))
11901190
```
11911191

11921192
> This matcher is only available in Swift.

Sources/Nimble/Matchers/PostNotification.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private let mainThread = pthread_self()
2929

3030
public func postNotifications(
3131
_ predicate: Predicate<[Notification]>,
32-
fromNotificationCenter center: NotificationCenter = .default
32+
from center: NotificationCenter = .default
3333
) -> Predicate<Any> {
3434
_ = mainThread // Force lazy-loading of this value
3535
let collector = NotificationCollector(notificationCenter: center)
@@ -66,12 +66,18 @@ public func postNotifications(
6666
}
6767
}
6868

69+
@available(*, deprecated, renamed: "postNotifications(_:from:)")
70+
public func postNotifications(
71+
_ predicate: Predicate<[Notification]>,
72+
fromNotificationCenter center: NotificationCenter = .default
73+
) -> Predicate<Any> {
74+
return postNotifications(predicate, from: center)
75+
}
76+
6977
public func postNotifications<T>(
7078
_ notificationsMatcher: T,
71-
fromNotificationCenter center: NotificationCenter = .default)
72-
-> Predicate<Any>
73-
where T: Matcher, T.ValueType == [Notification]
74-
{
79+
from center: NotificationCenter = .default
80+
)-> Predicate<Any> where T: Matcher, T.ValueType == [Notification] {
7581
_ = mainThread // Force lazy-loading of this value
7682
let collector = NotificationCollector(notificationCenter: center)
7783
collector.startObserving()
@@ -98,3 +104,11 @@ public func postNotifications<T>(
98104
return PredicateResult(bool: match, message: failureMessage.toExpectationMessage())
99105
}
100106
}
107+
108+
@available(*, deprecated, renamed: "postNotifications(_:from:)")
109+
public func postNotifications<T>(
110+
_ notificationsMatcher: T,
111+
fromNotificationCenter center: NotificationCenter = .default
112+
)-> Predicate<Any> where T: Matcher, T.ValueType == [Notification] {
113+
return postNotifications(notificationsMatcher, from: center)
114+
}

Tests/NimbleTests/Matchers/PostNotificationTest.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
99
expect {
1010
// no notifications here!
1111
return nil
12-
}.to(postNotifications(beEmpty(), fromNotificationCenter: notificationCenter))
12+
}.to(postNotifications(beEmpty(), from: notificationCenter))
1313
}
1414

1515
func testPassesWhenExpectedNotificationIsPosted() {
1616
let testNotification = Notification(name: Notification.Name("Foo"), object: nil)
1717
expect {
1818
self.notificationCenter.post(testNotification)
19-
}.to(postNotifications(equal([testNotification]), fromNotificationCenter: notificationCenter))
19+
}.to(postNotifications(equal([testNotification]), from: notificationCenter))
2020
}
2121

2222
func testPassesWhenAllExpectedNotificationsArePosted() {
@@ -28,7 +28,7 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
2828
self.notificationCenter.post(n1)
2929
self.notificationCenter.post(n2)
3030
return nil
31-
}.to(postNotifications(equal([n1, n2]), fromNotificationCenter: notificationCenter))
31+
}.to(postNotifications(equal([n1, n2]), from: notificationCenter))
3232
}
3333

3434
func testFailsWhenNoNotificationsArePosted() {
@@ -37,7 +37,7 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
3737
expect {
3838
// no notifications here!
3939
return nil
40-
}.to(postNotifications(equal([testNotification]), fromNotificationCenter: self.notificationCenter))
40+
}.to(postNotifications(equal([testNotification]), from: self.notificationCenter))
4141
}
4242
}
4343

@@ -48,7 +48,7 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
4848
expect {
4949
self.notificationCenter.post(n2)
5050
return nil
51-
}.to(postNotifications(equal([n1]), fromNotificationCenter: self.notificationCenter))
51+
}.to(postNotifications(equal([n1]), from: self.notificationCenter))
5252
}
5353
}
5454

@@ -59,7 +59,7 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
5959
expect {
6060
self.notificationCenter.post(n2)
6161
return nil
62-
}.to(postNotifications(equal([n1]), fromNotificationCenter: self.notificationCenter))
62+
}.to(postNotifications(equal([n1]), from: self.notificationCenter))
6363
}
6464
}
6565

@@ -70,6 +70,6 @@ final class PostNotificationTest: XCTestCase, XCTestCaseProvider {
7070
self.notificationCenter.post(testNotification)
7171
}
7272
return nil
73-
}.toEventually(postNotifications(equal([testNotification]), fromNotificationCenter: notificationCenter))
73+
}.toEventually(postNotifications(equal([testNotification]), from: notificationCenter))
7474
}
7575
}

0 commit comments

Comments
 (0)