RubyMotion Functional Tests with Storyboards

2 minute read Published:

If you’ve been using RubyMotion, you probably noticed that some new testing features were released today. The video in the announcment post and the documentation are pretty good, so I’m just going to share a few things that I had to do to get things working.


Both the video and documentation have you add a test environment guard clause to your application:didFinishLaunchingWithOptions: method in the application delegate. Be aware that this will likely cause the window test in the default main_spec.rb to fail, so either delete that or anticipate some test failures due to the initialization changes.

Project Configuration

Update 2012/07/14: The specs_dir is searched recursively now, so the workaround that was previously in this section is no longer needed.


Update 2012/07/21: Storyboards are now supported by passing an :id option. The documentation has not yet been updated, but the pending updates can be found on the RubyMotionDocumentation github page.

If you’re using Storyboards, you’ll have to pass the Xcode identifier of the controller to the tests method in the :id option.

# list_view_controller_spec.rb
describe 'list view' do

  # this call also extends the context with the test API methods
  tests ListViewController, :id => 'list-view-controller'

  it 'should have two cells by default' do
    views(UITableViewCell).count.should == 2


Spurious Errors

You may occasionally see errors like the following.

3 specifications (3 requirements), 0 failures, 0 errors
*** simulator session ended with error: Error Domain=DTiPhoneSimulatorErrorDomain Code=1 "The simulated application quit." UserInfo=0x10014de60 {NSLocalizedDescription=The simulated application quit., DTiPhoneSimulatorUnderlyingErrorCodeKey=-1}
rake aborted!
Command failed with status (1): [DYLD_FRAMEWORK_PATH="/Applications/Xcode.a...]

Tasks: TOP => simulator
(See full trace by running task with --trace)

I suspect this is the 0.3 second delay condition mentioned in the comments for the functional test code. Clearly the universe is telling me to get the new retina MBP.