calabash/calabash-ios — pull request #440 by jmoody (2014-07-21 20:50:40+00:00)
Title: reset app and sim content and settings (take 2)

## motivation

Replaces [PR #399 WIP reset app and sim content and settings](https://github.com/calabash/calabash-ios/pull/399).

Users have been reporting RESET_BETWEEN_SCENARIOS is not working.

After reviewing the code, I realized that `reset_app_jail` was only resetting the app sandbox for the most recent SDK _unless_ the SDK_VERSION environment variable is set. Since Xcode 5.1, we've been steering users away from SDK_VERSION in favor of DEVICE_TARGET.

This pull request addresses this issue by trying to detect the SDK from the DEVICE_TARGET environment variable. If the SDK version cannot be detected from the DEVICE_TARGET, all the app's sandboxes for _every_ SDKs are reset. Put another way, all SDK directories are searched and if the app appears, its sandbox is reset.

There are two reasons why the DEVICE_TARGET might not be set:

1. the user is a legacy user on Xcode < 5.1 or
2. the user is not setting DEVICE_TARGET and is instead relying on the default simulator to be used (e.g. 'iPhone Retina (4-inch) - Simulator - iOS 7.1')

I am not worried about the first case, but I am concerned about the second.

When no DEVICE_TARGET is set, the selection of 'iPhone Retina (4-inch) - Simulator - iOS 7.1' as the target simulator is done in the run_loop gem. It would be better, I think, if Calabash passed a simulator to run_loop.

With that said, I think the correct behavior should be to search the SDK directories for the app under test and reset every sandbox for the app, regardless of what SDK we are currently testing. This approach is clean and uncomplicated and usually the right thing to do.

#### other changes

1. Deprecated `reset_app_jail`; replaced with `reset_app_sandbox`. The deprecation is silent; there is no warning message.
2. Documented `reset_app_sandbox` with details about how to use `RESET_BETWEEN_SCENARIOS` and its behavior on the XTC and for devices outside of the XTC.
3. Added `reset_simulator` to Calabash::Cucumber::Launcher.

There was a minor bug in the reset-app algorithm that caused it to emit a unix-level file-not-found error.

## todo

@krukow

I would like to get some input on what the behavior of `reset_app_sandbox` should be. If you are fine with the behavior I've described above, let's merge this PR and work on a better solution.

## testing

I have a nice set of cucumbers at `test/cucumber` that demonstrate the changes. They can be run against devices, but will fail because `reset_app_sandbox` is not called; this is expected. They can also be run on the XTC, but there is one (explained) failure around a known bug in the keychain API on the XTC.

To run the cucumber tests:

```
$ cd calabash-ios
$ git fetch
$ git co -t feature/reset-app-and-sim-content-and-settings-take2
$ script/cucumber-ci
```

- [x] The tests against the simulators are run in travis-ci.`*`
- [x] iPad 4 iOS 7 - 2 expected failures
- [x] XTC https://testcloud.xamarin.com/s/hulyojbEDEDssQ

* The cucumber tests are flickering and take ~45 minutes to run. I think I should scale back the number of simulators I test on.

## links

* http://stackoverflow.com/questions/24493634/reset-ios-app-in-calabash-ios/24521084
* https://github.com/calabash/calabash-ios/issues/376