Roma-1

iOS acceptance testing with Calabash and Rspec

| 1 Comment

While investigating existing automated tools for mobile TDD, we have run into a well-documented and supported library by Xamarin. It’s called calabash, comes with iOS and Android support and has a wide scope of supported user actions, gestures and expectations.
The only drawback we found significant is lack of native Rspec support (cucumber only for now).
This post provides a simple tutorial for using calabash with Rspec to test your iOS applications.

Overview

Calabash library including сucumber step definitions is aggregated within single gem calabash-cucumber.
Basic tutorial for integrating your project with Calabash testing tool is well described here.
We use mixed approach for initial setup by adding Calabash pod and manually copying main project target in Xcode.
As cucumber is a primary framework coming out of the box, some additional steps are required to use it with Rspec.

Setting up Rspec environment

First of all install rspec gem and initialize your project:

This will generate the following file structure:

  • ./spec folder for all your test examples.
  • ./spec/spec_helper.rb file for all configuration and initial setup stuff.

Using predefined cucumber setup and a bit of source investigation, we came up with the following definitions within spec_helper.rb:

A before hook was set up to wait for any view to appear – such trick is required to avoid stupid failures because of initial simulator startup delay.
There are a few additional method definitions required to make this setup work:

You can add them to your spec_helper.rb.

Sugarize it

Basic ruby modules included in calabash-cucumber gem have predefined steps for

  • querying elements
  • performing actions/gestures
  • matching expectations

We have added simple wrapper methods to make test examples readable and DRY.
Here are some examples that are used in our test scenarios:

Step definitions

Custom matchers

Conclusions

Adding Rspec support for your acceptance testing using calabash library is really simple.
Approach described above helped us to build and support application test coverage for wide variety of flows and interactions.
Here is a short example on login flow test scenario:

Using Rspec instead of cucumber gives you a better opportunity to setup context of test examples.
It’s also very important to use any CI server you prefer as it takes some time for full test coverage to run.
Do not hesitate to add your own step definitions and matchers to keep your test examples readable, DRY and clean.

Share
* Railsware is a premium software development consulting company, focused on delivering great web and mobile applications. Learn more about us.
  • Matt

    Thanks for sharing! This is great, I knew there were some caveats to using Rspec, I’m excited to try this out, and reap the benefits

Want to get more of Railsware blog?

RSS FEED

We're always ready to help!

CONTACT US