• Stars
    star
    281
  • Rank 143,045 (Top 3 %)
  • Language
    Objective-C
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TUDelorean helps you test your time-dependent Objetive-C code allowing you travel anywhere in time.

TUDelorean

Marty: “Wait a minute. Wait a minute. Doc, uh.… Are you telling me that you built a time machine.… out of a DeLorean?”

Doc: “Yes, the way I see it, if you’re gonna build a time machine into a car, why not do it with some style?”

Build Status

A DeLorean helps you test your time-dependent code allowing you travel anywhere in time.

This simple class provides several class methods to perform diferent time mannipulations that will modify the behaviour of NSDate instances and how time advances during the span the manipulation effects are enabled.

The intention of this class is to be used during testing, so reproducible scenarios can be designed and tested. This class should not be used in production code.

How to use

Installing

Using CocoaPods

  1. Include the following line in your Podfile:
    pod 'TUDelorean', :git => 'https://github.com/tuenti/TUDelorean'
    
  2. Run pod install

Manually

  1. Clone, add as a submodule or download TUDelorean.
  2. Add all the files under Classes/common to your project.
  3. Look at the Requirements section if you are not using ARC.

Coding

TUDelorean only provides one header that you must import in order to use the library. Simply add #import "TUDelorean.h" at the top of your testing files where you want to use TUDelorean.

One thing that you must remember is that in any test case you decide to use TUDelorean you must call backToThePresent in its tearDown (or equivalent) method. Otherwise the effects of changing the current time will “leak” to other tests and also the testing rig.

- (void)tearDown
{
    [TUDelorean backToThePresent];
}

TUDelorean offers three primitives to change the current time. Each of them has two variants: in one of them the effects of the time manipulation are permanent, while in the other one the effects of the time manipulation only affects the block passed as parameter. You are encouraged to use the block-based versions, to improve the readability of your tests.

The first primitive is “time travelling”. You provide a destination date, and the current time will be reported from that point as in the past or in the future.

NSDate *destination = [NSDate dateWithNaturalLanguageString:@"November 12, 1955"];
[TUDelorean timeTravelTo:destination block:^(NSDate *date) {
    // Inside the block its November 12, 1955
    [marty playGuitar:@"Johnny B. Goode"];
}];

The second primitive is a relative “time jump”. You provide an offset from the current time, and from that point the current time will be displaced the number of seconds you wanted.

[timeMachine addOccupant:einstein];
[TUDelorean jump:60 block:^(NSDate *date) {
    // Inside the block its already 60 seconds into the future
    [einstein woof];
}];
[marty say:@"Jesus Christ, Doc. You disintegrated Einstein!"]

The final primitive is another time jump, but instead of allowing the time to keep flowing as normal, the time is frozen in the same moment. This is particurlaly useful if you need to do time distance calculations, and you want to test the edge cases.

NSDate *destination = [NSDate dateWithNaturalLanguageString:@"18pm September 5, 1885"];
[TUDelorean freeze:destination block:^(NSDate *date) {
    // Inside the block is 18pm September 5, 1885.
    [NSThread sleepForTimeInterval:3600.0];
    // Yes, still 18pm September 5, 1885.
}];

You can reset the changes done to the current time using backToThePresent at any moment.

Requirements

TUDelorean should work in any relatively recent iOS/Mac version, but we have only tested it iOS 6.0 and OS X 10.8. We have only tested TUDelorean with OCUnit, but it should work in any other testing framework unchanged.

TUDelorean uses ARC, so if you use it in a non-ARC project, and you are not using CocoaPods, you will need to use -fobjc-arc compiler flag on every TUDelorean source file.

To set a compiler flag in Xcode, go to your desidered target and select the “Build Phases” tab. Select all TUDelorean source files, press Enter, add -fobjc-arc and then “Done” to enable ARC for TUDelorean.

Credits & Contact

TUDelorean was created by iOS team at Tuenti Technologies S.L.. You can follow Tuenti engineering team on Twitter @tuentieng.

TUDelorean was inspired by the similarly named Rubygem delorean. Thanks for the inspiration, and for finding this awesome name.

License

TUDelorean is available under the Apache License, Version 2.0. See LICENSE file for more info.

More Repositories

1

ButtonMenu

ButtonMenu is an Android library created to build user interfaces based on buttons. This library has been implemented using Model View ViewModel pattern combined with an Android custom view that extends LinearLayout.
Java
441
star
2

SmsRadar

Android library created to listen incoming and outgoing SMS's
Java
390
star
3

secrets-manager

A daemon to sync Vault secrets to Kubernetes secrets
Go
171
star
4

activity-detector

Simple js module to detect when the user is really using your page
JavaScript
133
star
5

TUScheduler

TUScheduler is a very simple iOS library that solves the problem of asynchronous testing in an elegant and robust way. Furthermore, TUScheduler allows you to decouple your code from the underlying concurrency API.
Objective-C
36
star
6

animated-circle-progress-view

Progress view that animates its state changes.
Java
35
star
7

VideoRecorderService

VideoRecorderService is a lightweight web-based service that offers a REST interface to easily manage the recording of screen videos.
Java
34
star
8

pouch

Tools to provision secrets using Vault with AppRole authentication method
Go
31
star
9

sdp-to-jingle-java

Java
27
star
10

ikusth

Threads dependency graph generator
Java
25
star
11

kube2lb

Dinamically configure load balancers to expose Kubernetes services
Go
22
star
12

TMAERecorder

AVAudioRecorder replacement which allows audio recording with real time sound filtering. Implemented using The Amazing Audio Engine.
Objective-C
20
star
13

hiphop-php

Source code transformer from PHP to C++
C++
18
star
14

programming-challenge-2

Solutions and writeups from participants of the Tuenti Programming Challenge 2
Java
17
star
15

android-deferred

Java
14
star
16

python-repoman

Repoman is a python library designed to automate repository operations in release processes.
Python
13
star
17

TMInstanceMethodSwizzler

Method swizzling library for Objetive-C
Objective-C
13
star
18

TMDebugConsole

TMDebugConsole is a simple in-app console to be used with Cocoa Lumberjack. It allows you to see your logs on the device, without needing to be paired with a debug session in XCode, using different colors for errors, warnings, and informative messages
Objective-C
9
star
19

ldap-expire-notify

ldap-expire-notify is a tool to notify your LDAP users when their password is about to expire. It supports several kind of notification channels.
Python
9
star
20

supernanny

Java
8
star
21

haproxy-docker-wrapper

Docker-friendly wrapper for haproxy
Go
7
star
22

pyflapjackevents

Pyflapjackevents is a small library that serializes Flapjack events for the Python language
Python
7
star
23

simtron

TypeScript
4
star
24

php-json-rpc

Tuenti's implementation of json rpc according to the json-rpc spec 2.0 excluding events and batches. It provides the implementation of the objects described in the implementation and a json-rpc client.
PHP
4
star
25

tuenti-star-validator

Submission validator and score calculator for #TuentiChallenge6's Tuenti Star challenge
OCaml
4
star
26

geoip

C
1
star
27

tuenti-php-sdk

Tuenti PHP SDK for Applications
PHP
1
star