Inherits from NSObject
Declared in RKTestNotificationObserver.h

Overview

An RKTestNotificationObserver object provides support for awaiting a notification to be posted as the result of an asynchronous operation by spinning the run loop. This enables a straight-forward unit testing workflow by blocking execution of the test until a notification is posted.

Tasks

Properties

name

The name of the notification the receiver is awaiting.

@property (nonatomic, copy) NSString *name

Declared In

RKTestNotificationObserver.h

object

The object expected to post the notification the receiver is awaiting.

@property (nonatomic, weak) id object

Discussion

Can be nil.

Declared In

RKTestNotificationObserver.h

timeout

The timeout interval, in seconds, to wait for the notification to be posted.

@property (nonatomic, assign) NSTimeInterval timeout

Discussion

Default: 3 seconds

Declared In

RKTestNotificationObserver.h

Class Methods

notificationObserver

Creates and initializes a notification obsercer object.

+ (RKTestNotificationObserver *)notificationObserver

Return Value

The newly created notification observer.

Declared In

RKTestNotificationObserver.h

notificationObserverForName:

Instantiate a notification observer for the given notification name

+ (RKTestNotificationObserver *)notificationObserverForName:(NSString *)notificationName

Parameters

notificationName

The name of the NSNotification we want to watch for

Declared In

RKTestNotificationObserver.h

notificationObserverForName:object:

Instantiate a notification observer for the given notification name and object

+ (RKTestNotificationObserver *)notificationObserverForName:(NSString *)notificationName object:(id)notificationSender

Parameters

notificationName

The name of the NSNotification we want to watch for

notificationSender

The source object of the NSNotification we want to watch for

Return Value

The newly created notification observer initialized with notificationName and notificationSender.

Declared In

RKTestNotificationObserver.h

waitForNotificationWithName:object:usingBlock:

Configures a notification observer to wait for the a notification with the given name to be posted by the source object during execution of the block.

+ (void)waitForNotificationWithName:(NSString *)name object:(id)notificationSender usingBlock:(void ( ^ ) ( ))block

Parameters

name

The name of the notification we are waiting for

notificationSender

The object we are waiting to post the notification

block

A block to invoke to trigger the notification activity

Declared In

RKTestNotificationObserver.h

waitForNotificationWithName:usingBlock:

Configures a notification observer to wait for the a notification with the given name to be posted during execution of the block.

+ (void)waitForNotificationWithName:(NSString *)name usingBlock:(void ( ^ ) ( ))block

Parameters

name

The name of the notification we are waiting for

block

A block to invoke to trigger the notification activity

Declared In

RKTestNotificationObserver.h

Instance Methods

addObserver

Adds the receiver as an observer for the notification name and object under test.

- (void)addObserver

Discussion

If the observer has not already been added when waitForNotification is invoked, it will be added before the runloop cycling begins.

Declared In

RKTestNotificationObserver.h

waitForNotification

Wait for a notification matching the name and source object we are observing to be posted.

- (void)waitForNotification

Discussion

This method will block by spinning the runloop waiting for an appropriate notification matching our observed name and object to be posted or the timeout configured is exceeded.

Declared In

RKTestNotificationObserver.h