lib/calabash-cucumber/keychain_helpers.rb in calabash-cucumber-0.14.2.pre1 vs lib/calabash-cucumber/keychain_helpers.rb in calabash-cucumber-0.14.2

- old
+ new

@@ -27,12 +27,18 @@ # @see #keychain_account_for_service # @return [Array<Hash>] contents of the iOS keychain # @param [Hash] options # @raise [RuntimeError] if http request does not report success def _keychain_get(options={}) - res = http({:method => :get, :raw => true, :path => 'keychain'}, options) - res = JSON.parse(res) + raw = http({:method => :get, :raw => true, :path => 'keychain'}, options) + + begin + res = JSON.parse(raw) + rescue TypeError, JSON::ParserError => _ + raise "Could not parse response '#{res}'; the app might have crashed or the server responded with invalid JSON." + end + if res['outcome'] != 'SUCCESS' raise "get keychain with options '#{options}' failed because: '#{res['reason']}'\n'#{res['details']}'" end res['results'] @@ -103,14 +109,18 @@ # # @return [nil] # @raise [RuntimeError] if http request does not report success def _keychain_post(options={}) raw = http({:method => :post, :path => 'keychain'}, options) - res = JSON.parse(raw) + begin + res = JSON.parse(raw) + rescue TypeError, JSON::ParserError => _ + raise "Could not parse response '#{res}'; the app might have crashed or the server responded with invalid JSON." + end if res['outcome'] != 'SUCCESS' raise "post keychain with options '#{options}' failed because: #{res['reason']}\n#{res['details']}" end - nil + res['results'] end # On the iOS Simulator this clears *all* keychain entries for *all* # applications. #