Skip to content

Instantly share code, notes, and snippets.

View tibr's full-sized avatar

Tim Brückmann tibr

View GitHub Profile
View gist:441ea71c8c0fd69bca58
func fetchNotificationsNotMatchingEtag(etag: String?, includeReadNotifications includeRead: Bool, updatedSince since: NSDate?) -> SignalProducer<OCTResponse, NSError> {
let signal = fetchNotificationsNotMatchingEtag(etag, includeReadNotifications: includeRead, updatedSince: since)
return signal.toSignalProducer()
|> map { $0 as! OCTResponse }
tibr / gist:2001574
Created March 8, 2012 15:43
Stubbing alloc to return mocked object
View gist:2001574
it(@"should start the processing with the ids from the network response", ^{
// mock network request
[KWSpec canResponseJSON:@"ids"];
// execute code under test
[client syncMyStuff];
// create mock
id process = [ProcessingOperation mock];
// return mock by stubbing alloc
tibr / gist:5781595
Created June 14, 2013 12:56
stub context example
View gist:5781595
context(@"success", ^{
[OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request) {
NSString *expectedPath = @"/3/configuration";
BOOL shouldStub = [[request.URL path] isEqualToString:expectedPath];
return shouldStub;
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
OHHTTPStubsResponse *response = [OHHTTPStubsResponse responseWithFile:@"configuration.json"
tibr / gist:6187127
Created August 8, 2013 18:12
UIScrollView needs a subview with an absolute width value to use it's full width as contentSize. I'm trying to use a helper view here to make sure it always uses it's own width as it's content width.
View gist:6187127
UIView *scrollViewWidthEnforcer = [UIView new];
[scrollViewWidthEnforcer setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.scrollView addSubview:scrollViewWidthEnforcer];
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[enforcer(==scrollView)]|"
@"enforcer" : scrollViewWidthEnforcer,
@"scrollView" : self.scrollView
tibr / XCTestCase+OCUnitCompatibility.m
Created September 18, 2013 12:08
SenTestingKit => XCTestCase exception handling
View XCTestCase+OCUnitCompatibility.m
- (void)failWithException:(NSException *)exception
NSRange firstColonRange = [exception.reason rangeOfString:@":"];
NSString *filename = [exception.reason substringToIndex:firstColonRange.location];
NSString *secondPart = [exception.reason substringFromIndex:firstColonRange.location + firstColonRange.length];
NSRange lineSeparatorRange = [secondPart rangeOfString:@" "];
NSString *lineString = [secondPart substringToIndex:lineSeparatorRange.location];
tibr / NSFileManager+DoNotBackup.h
Created March 8, 2012 09:42
Setting the do not backup attribute in different iOS versions
View NSFileManager+DoNotBackup.h
@interface NSFileManager (DoNotBackup)
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;