square/KIF — pull request #103 by blakewatters (2012-01-07 21:53:29+00:00)
Title: Add Step for Observing Notifications Emited During Child Step Execution

When building KIF integration tests for the GateGuru application, I have been making extensive use of notifications to observe for state changes as the result of some UI interactions rather than accessibility labeled elements. We use Three20's URL dispatching within the app, which allows us to directly open view controllers from our KIF steps and then execute interaction steps. This lets us quickly build focused tests for particular screens (especially modal view controllers) that drop out after a button has been pressed (i.e. save, login, logout, etc). Since we don't necessarily know what is going to be behind the controller when it is dismissed, I have been using `stepToWaitForNotificationName:object:` to watch for notifications posted from the data model to determine success.

The issue I have been running into is the observer step will sometimes fail because the observer is not registered until the step executes and the previous step in the scenario is taking the action that results in the notification being posted.

To remedy this, I have implemented `stepToWaitForNotificationName:object:whileExecutingStep:`. This step registers an observer, then executes the child step to completion, and then waits for the notification. This has made the brittle tests totally reliable.