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

@property (nonatomic, copy) NSString *name
Discussion

The name of the notification the receiver is awaiting.

Declared In

RKTestNotificationObserver.h

object

@property (nonatomic, weak) id object
Discussion

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

Can be nil.

Declared In

RKTestNotificationObserver.h

timeout

@property (nonatomic, assign) NSTimeInterval timeout
Discussion

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

Default: 3 seconds

Declared In

RKTestNotificationObserver.h

Class Methods

notificationObserver

+ (RKTestNotificationObserver *)notificationObserver
Discussion

Creates and initializes a notification obsercer object.

Return Value

The newly created notification observer.

Declared In

RKTestNotificationObserver.h

notificationObserverForName:

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

Instantiate a notification observer for the given notification name

Parameters

notificationName

The name of the NSNotification we want to watch for

Declared In

RKTestNotificationObserver.h

notificationObserverForName:object:

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

Instantiate a notification observer for the given notification name and object

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:

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

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.

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:

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

Configures a notification observer to wait for the a notification with the given name to be posted during execution of the 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

- (void)addObserver
Discussion

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

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

- (void)waitForNotification
Discussion

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

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