Reset the iOS simulator using Frank

Frank page has some step definitions contributed by users.

The step for resetting the simulator is very useful, as there is some state in the App, and it's hard to test around it.

For example if you have a "Rate me" dialog popping up on the third time user opens the app or an ad, that shows fullscreen, but not on the first run. There's also no telling on which screen those things will show, as a network call is required. Writing frank steps around those things is overly complicated.

The step for resetting the simulator fixes all this, as it resets NSUserDefaults, but the one on the community page is outdated.

I wrote one that works on Xcode 6.1 with iOS 8.1 simulator:

Given /^I reset the app$/ do

  application_dir = "/Users/#{ENV['USER']}/Library/Developer/CoreSimulator/Devices"
  userdefaults_plist = "data/Library/Preferences/"
  Dir.foreach(applications_dir) do |item|
    next if item == '.' or item == '..'

    preferences_dir = "#{application_dir}/#{item}/#{userdefaults_plist}"
    if File::exists?(preferences_dir)
      Dir.foreach(preferences_dir) do |pref|
        if pref.include? "com.wikia"
          FileUtils.rm preferences_dir + '/' + pref

This has a caveat of removing all preferences from Apps with the com.wikia bundle identifier prefix. This isn't a big problem, as the simulator can run only one App at once and in general you should reset the app before every test.