Skip to content

Commit

Permalink
Initial import, got the first two basic functional tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeredpath committed Jul 22, 2010
0 parents commit b946a4d
Show file tree
Hide file tree
Showing 25 changed files with 1,299 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
*.pbxproj -crlf -diff -merge
34 changes: 34 additions & 0 deletions .gitignore
@@ -0,0 +1,34 @@
# Mac OS X Finder and whatnot
.DS_Store

# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser


# Generated files
VersionX-revision.h


# build products
build/
*.[oa]

# Other source repository archive directories (protects when importing)
.hg
.svn
CVS


# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/
16 changes: 16 additions & 0 deletions Classes/LRMiniTestKit/LRExpectation.h
@@ -0,0 +1,16 @@
//
// LRExpectation.h
// Mocky
//
// Created by Luke Redpath on 22/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol LRExpectation
- (BOOL)matches:(NSInvocation *)invocation;
- (void)invoke:(NSInvocation *)invocation;
- (BOOL)isSatisfied;
- (NSException *)failureException;
@end
21 changes: 21 additions & 0 deletions Classes/LRMiniTestKit/LRExpectationBuilder.h
@@ -0,0 +1,21 @@
//
// LRExpectationBuilder.h
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <Foundation/Foundation.h>

@class LRMockObject;
@class LRMockery;

@interface LRExpectationBuilder : NSObject {
LRMockery *mockery;
Class mockedClass;
}
+ (id)builderInContext:(LRMockery *)context;
- (id)initWithMockery:(LRMockery *)aMockery;
- (id)expect:(id)mockObject;
@end
56 changes: 56 additions & 0 deletions Classes/LRMiniTestKit/LRExpectationBuilder.m
@@ -0,0 +1,56 @@
//
// LRExpectationBuilder.m
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import "LRExpectationBuilder.h"
#import "LRMockObject.h"
#import "LRMockery.h"
#import "LRInvocationExpectation.h"

@implementation LRExpectationBuilder

+ (id)builderInContext:(LRMockery *)context;
{
return [[[self alloc] initWithMockery:context] autorelease];
}

- (id)initWithMockery:(LRMockery *)aMockery;
{
if (self = [super init]) {
mockery = [aMockery retain];
}
return self;
}

- (void)dealloc;
{
[mockery release];
[super dealloc];
}

- (id)expect:(id)mockObject;
{
mockedClass = [(LRMockObject *)mockObject mockedClass];
return self;
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
return [mockedClass instanceMethodSignatureForSelector:sel];
}

- (BOOL)respondsToSelector:(SEL)aSelector
{
return [mockedClass instancesRespondToSelector:aSelector];
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
[mockery addExpectation:[LRInvocationExpectation expectationWithInvocation:invocation]];
}

@end
19 changes: 19 additions & 0 deletions Classes/LRMiniTestKit/LRExpectationProxy.h
@@ -0,0 +1,19 @@
//
// LRExpectationProxy.h
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface LRExpectationProxy : NSProxy {
Class proxiedClass;
NSMutableArray *expectations;
}
+ (id)proxyForClass:(Class)aClass;
- (id)initWithClass:(Class)aClass;
- (BOOL)hasExpectationMatchingInvocation:(NSInvocation *)invocation;
@end
56 changes: 56 additions & 0 deletions Classes/LRMiniTestKit/LRExpectationProxy.m
@@ -0,0 +1,56 @@
//
// LRExpectationProxy.m
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import "LRExpectationProxy.h"
#import "LRInvocationExpectation.h"

@implementation LRExpectationProxy

+ (id)proxyForClass:(Class)aClass;
{
return [[[self alloc] initWithClass:aClass] autorelease];
}

- (id)initWithClass:(Class)aClass;
{
proxiedClass = aClass;
expectations = [[NSMutableArray alloc] init];

return self;
}

- (void)dealloc;
{
[expectations release];
[super dealloc];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
return [proxiedClass instanceMethodSignatureForSelector:sel];
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
[expectations addObject:[LRInvocationExpectation expectationWithInvocation:invocation]];
}

- (BOOL)respondsToSelector:(SEL)aSelector
{
return [proxiedClass instancesRespondToSelector:aSelector];
}

- (BOOL)hasExpectationMatchingInvocation:(NSInvocation *)invocation;
{
for (LRInvocationExpectation *expectation in expectations) {
if ([expectation matches:invocation]) return YES;
}
return NO;
}

@end
18 changes: 18 additions & 0 deletions Classes/LRMiniTestKit/LRInvocationExpectation.h
@@ -0,0 +1,18 @@
//
// LRInvocationExpectation.h
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LRExpectation.h"

@interface LRInvocationExpectation : NSObject <LRExpectation> {
NSInvocation *expectedInvocation;
NSUInteger numberOfInvocations;
}
+ (id)expectationWithInvocation:(NSInvocation *)anInvocation;
- (id)initWithInvocation:(NSInvocation *)anInvocation;
@end
57 changes: 57 additions & 0 deletions Classes/LRMiniTestKit/LRInvocationExpectation.m
@@ -0,0 +1,57 @@
//
// LRInvocationExpectation.m
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import "LRInvocationExpectation.h"


@implementation LRInvocationExpectation

+ (id)expectationWithInvocation:(NSInvocation *)anInvocation;
{
return [[[self alloc] initWithInvocation:anInvocation] autorelease];
}

- (id)initWithInvocation:(NSInvocation *)anInvocation;
{
if (self = [super init]) {
expectedInvocation = [anInvocation retain];
numberOfInvocations = 0;
}
return self;
}

- (void)dealloc;
{
[expectedInvocation release];
[super dealloc];
}

- (BOOL)matches:(NSInvocation *)invocation;
{
if ([invocation selector] != [expectedInvocation selector]) {
return NO;
}
return YES;
}

- (void)invoke:(NSInvocation *)invocation
{
numberOfInvocations++;
}

- (BOOL)isSatisfied;
{
return numberOfInvocations > 0;
}

- (NSException *)failureException;
{
return [NSException exceptionWithName:@"test failure" reason:@"just testing" userInfo:nil];
}

@end
21 changes: 21 additions & 0 deletions Classes/LRMiniTestKit/LRMockObject.h
@@ -0,0 +1,21 @@
//
// LRMockObject.h
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <Foundation/Foundation.h>

@class LRMockery;

@interface LRMockObject : NSObject {
Class mockedClass;
LRMockery *context;
}
@property (nonatomic, readonly) Class mockedClass;

+ (id)mockForClass:(Class)aClass inContext:(LRMockery *)mockery;
- (id)initWithClass:(Class)aClass context:(LRMockery *)mockery;
@end
51 changes: 51 additions & 0 deletions Classes/LRMiniTestKit/LRMockObject.m
@@ -0,0 +1,51 @@
//
// LRMockObject.m
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import "LRMockObject.h"
#import "LRMockery.h"

@implementation LRMockObject

@synthesize mockedClass;

+ (id)mockForClass:(Class)aClass inContext:(LRMockery *)mockery;
{
return [[[self alloc] initWithClass:aClass context:mockery] autorelease];
}

- (id)initWithClass:(Class)aClass context:(LRMockery *)mockery;
{
if (self = [super init]) {
mockedClass = aClass;
context = [mockery retain];
}
return self;
}

- (void)dealloc;
{
[context release];
[super dealloc];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
return [mockedClass instanceMethodSignatureForSelector:sel];
}

- (BOOL)respondsToSelector:(SEL)aSelector
{
return [mockedClass instancesRespondToSelector:aSelector];
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
[context dispatchInvocation:invocation];
}

@end
28 changes: 28 additions & 0 deletions Classes/LRMiniTestKit/LRMockery.h
@@ -0,0 +1,28 @@
//
// LRMockery.h
// LRMiniTestKit
//
// Created by Luke Redpath on 18/07/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LRExpectation.h"
#import "LRTestCase.h"

@class LRExpectationBuilder;
@class SenTestCase;

@interface LRMockery : NSObject {
NSMutableArray *expectations;
id<LRTestCase> testCase;
}
+ (id)mockeryForSenTestCase:(SenTestCase *)testCase;
+ (id)mockeryForTestCase:(id<LRTestCase>)testCase;
- (id)initWithTestCase:(id<LRTestCase>)aTestCase;
- (id)mock:(Class)klass;
- (void)checking:(void (^)(LRExpectationBuilder *will))expectationBlock;
- (void)addExpectation:(id<LRExpectation>)expectation;
- (void)assertSatisfied;
- (void)dispatchInvocation:(NSInvocation *)invocation;
@end

0 comments on commit b946a4d

Please sign in to comment.