@@ -151,94 +151,6 @@ public extension XCTestCase {
151
151
completionHandler ( error)
152
152
}
153
153
}
154
-
155
- /// Creates and returns an expectation for a notification.
156
- ///
157
- /// - Parameter notificationName: The name of the notification the
158
- /// expectation observes.
159
- /// - Parameter object: The object whose notifications the expectation will
160
- /// receive; that is, only notifications with this object are observed by
161
- /// the test case. If you pass nil, the expectation doesn't use
162
- /// a notification's object to decide whether it is fulfilled.
163
- /// - Parameter handler: If provided, the handler will be invoked when the
164
- /// notification is observed. It will not be invoked on timeout. Use the
165
- /// handler to further investigate if the notification fulfills the
166
- /// expectation.
167
- @discardableResult func expectation( forNotification notificationName: String , object objectToObserve: AnyObject ? , handler: XCNotificationExpectationHandler ? = nil ) -> XCTestExpectation {
168
- let objectDescription = objectToObserve == nil ? " any object " : " \( objectToObserve!) "
169
- let expectation = self . expectation ( description: " Expect notification ' \( notificationName) ' from " + objectDescription)
170
- // Start observing the notification with specified name and object.
171
- var observer : NSObjectProtocol ? = nil
172
- func removeObserver( ) {
173
- if let observer = observer {
174
- NotificationCenter . default. removeObserver ( observer)
175
- }
176
- }
177
-
178
- weak var weakExpectation = expectation
179
- observer = NotificationCenter
180
- . default
181
- . addObserver ( forName: Notification . Name ( rawValue: notificationName) ,
182
- object: objectToObserve,
183
- queue: nil ,
184
- usingBlock: {
185
- notification in
186
- guard let expectation = weakExpectation else {
187
- removeObserver ( )
188
- return
189
- }
190
-
191
- // If the handler is invoked, the test will
192
- // only pass if true is returned.
193
- if let handler = handler {
194
- if handler ( notification) {
195
- expectation. fulfill ( )
196
- removeObserver ( )
197
- }
198
- } else {
199
- expectation. fulfill ( )
200
- removeObserver ( )
201
- }
202
- } )
203
-
204
- return expectation
205
- }
206
-
207
- /// Creates and returns an expectation that is fulfilled if the predicate
208
- /// returns true when evaluated with the given object. The expectation
209
- /// periodically evaluates the predicate and also may use notifications or
210
- /// other events to optimistically re-evaluate.
211
- ///
212
- /// - Parameter predicate: The predicate that will be used to evaluate the
213
- /// object.
214
- /// - Parameter object: The object that is evaluated against the conditions
215
- /// specified by the predicate.
216
- /// - Parameter file: The file name to use in the error message if
217
- /// this expectation is not waited for. Default is the file
218
- /// containing the call to this method. It is rare to provide this
219
- /// parameter when calling this method.
220
- /// - Parameter line: The line number to use in the error message if the
221
- /// this expectation is not waited for. Default is the line
222
- /// number of the call to this method in the calling file. It is rare to
223
- /// provide this parameter when calling this method.
224
- /// - Parameter handler: A block to be invoked when evaluating the predicate
225
- /// against the object returns true. If the block is not provided the
226
- /// first successful evaluation will fulfill the expectation. If provided,
227
- /// the handler can override that behavior which leaves the caller
228
- /// responsible for fulfilling the expectation.
229
- @discardableResult func expectation( for predicate: NSPredicate , evaluatedWith object: AnyObject , file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler ? = nil ) -> XCTestExpectation {
230
- let expectation = XCPredicateExpectation (
231
- predicate: predicate,
232
- object: object,
233
- description: " Expect ` \( predicate) ` for object \( object) " ,
234
- file: file,
235
- line: line,
236
- testCase: self ,
237
- handler: handler)
238
- _allExpectations. append ( expectation)
239
- expectation. considerFulfilling ( )
240
- return expectation
241
- }
242
154
}
243
155
244
156
internal extension XCTestCase {
0 commit comments