Testing App UI and Controllers

In addition to a basic RSpec testing framework, RubyMotion includes extensions that help us test complex interactions with views and a device. You can specifically test events such as taps, flicks, and pinches to ensure that your callbacks are functioning accordingly.

Let’s walk through an example of RubyMotion’s UI test helpers. We’re going to programmatically tap a UIButton and assert that some state has changed after the tap. Even better, we’ll make sure to visibly alter the UI after the tap to make it obvious while the test is running in the simulator.

Since UI testing requires a UIViewController instance, we need one of our own. Create the app/controllers directory and a button_controllerrb file within. ...

Get RubyMotion now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.