Skip to content

Commit

Permalink
Fix tests for PostNotificationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
younata committed Apr 11, 2023
1 parent 6da2b50 commit 7077121
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Nimble.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
857D184F2536124400D8693A /* BeWithinTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 857D184D2536123F00D8693A /* BeWithinTest.swift */; };
857D18502536124400D8693A /* BeWithinTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 857D184D2536123F00D8693A /* BeWithinTest.swift */; };
857D18512536124500D8693A /* BeWithinTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 857D184D2536123F00D8693A /* BeWithinTest.swift */; };
8913626D29E5C2F500AD535E /* BackgroundThreadObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F5CD6427EE571C00B19809 /* BackgroundThreadObject.swift */; };
892FDF1329D3EA7700523A80 /* AsyncExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892FDF1229D3EA7700523A80 /* AsyncExpression.swift */; };
892FDF1429D3EA7700523A80 /* AsyncExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892FDF1229D3EA7700523A80 /* AsyncExpression.swift */; };
892FDF1529D3EA7700523A80 /* AsyncExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892FDF1229D3EA7700523A80 /* AsyncExpression.swift */; };
Expand Down Expand Up @@ -2143,6 +2144,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8913626D29E5C2F500AD535E /* BackgroundThreadObject.swift in Sources */,
D95F8945267EA1E8004B1B4D /* BeNilTest.swift in Sources */,
D95F8949267EA1E8004B1B4D /* MatchTest.swift in Sources */,
D95F8951267EA1EE004B1B4D /* utils.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Tests/NimbleTests/Helpers/BackgroundThreadObject.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Nimble

// Simulates an object that *really* cares what thread it is run on.
// Supposed to replicate what happens if a NSManagedObject ends up
Expand Down
22 changes: 11 additions & 11 deletions Tests/NimbleTests/Matchers/PostNotificationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,32 @@ final class PostNotificationTest: XCTestCase {
let n2 = Notification(name: Notification.Name(n1.name.rawValue + "a"), object: nil)
expect {
self.notificationCenter.post(n2)
}.toEventuallyNot(postNotifications(equal([n1]), from: self.notificationCenter))
}.toNever(postNotifications(equal([n1]), from: self.notificationCenter))
}

func testPassesWhenNotificationIsPostedFromADifferentThread() {
let n1 = Notification(name: Notification.Name("Foo"), object: nil)
expect {
DispatchQueue.global(qos: .userInitiated).async {
OperationQueue().addOperations([BlockOperation {
let backgroundThreadObject = BackgroundThreadObject()
let n2 = Notification(name: Notification.Name(n1.name.rawValue + "a"), object: backgroundThreadObject)
let n2 = Notification(name: Notification.Name("Bar"), object: backgroundThreadObject)
self.notificationCenter.post(n2)
}
}], waitUntilFinished: true)
self.notificationCenter.post(n1)
}.toEventually(postNotifications(contain([n1]), from: notificationCenter))
}.to(postNotifications(contain([n1]), from: notificationCenter))
}

func testPassesWhenNotificationIsPostedFromADifferentThreadAndToEventuallyNotCalled() {
func testPassesWhenNotificationIsPostedFromADifferentThreadAndToNotCalled() {
let n1 = Notification(name: Notification.Name("Foo"), object: nil)
expect {
DispatchQueue.global(qos: .userInitiated).async {
OperationQueue().addOperations([BlockOperation {
let backgroundThreadObject = BackgroundThreadObject()
let n2 = Notification(name: Notification.Name(n1.name.rawValue + "a"), object: backgroundThreadObject)
self.notificationCenter.post(n2)
}
}.toEventuallyNot(postNotifications(equal([n1]), from: notificationCenter))
}], waitUntilFinished: true)
}.toNot(postNotifications(equal([n1]), from: notificationCenter))
}

#if os(macOS)
func testPassesWhenAllExpectedNotificationsarePostedInDistributedNotificationCenter() {
let center = DistributedNotificationCenter()
Expand Down

0 comments on commit 7077121

Please sign in to comment.