Permalink
Browse files

Added tests for DBValidationStringLengthRule, updated website in readme

  • Loading branch information...
daniel-beard committed May 11, 2013
1 parent bf30e68 commit cb51ec61423a1e8b5b20c1f6b989372a67470957
@@ -12,6 +12,8 @@
2B5850B9173E37AD003F2D71 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DA0CBB169CFC0200CE09AD /* Foundation.framework */; };
2B5850BF173E37AD003F2D71 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2B5850BD173E37AD003F2D71 /* InfoPlist.strings */; };
2B5850C2173E37AD003F2D71 /* DBValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B5850C1173E37AD003F2D71 /* DBValidatorTests.m */; };
+ 2B5850CB173E49EB003F2D71 /* DBStringLengthRuleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B5850CA173E49EB003F2D71 /* DBStringLengthRuleTests.m */; };
+ 2B5850D1173E4A62003F2D71 /* DBDummyClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B5850D0173E4A62003F2D71 /* DBDummyClass.m */; };
65071148169D3EF700489DA0 /* DBValidationNumberRangeRule.m in Sources */ = {isa = PBXBuildFile; fileRef = 65071147169D3EF700489DA0 /* DBValidationNumberRangeRule.m */; };
65DA0CBA169CFC0200CE09AD /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DA0CB9169CFC0200CE09AD /* UIKit.framework */; };
65DA0CBC169CFC0200CE09AD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DA0CBB169CFC0200CE09AD /* Foundation.framework */; };
@@ -50,6 +52,9 @@
2B5850C0173E37AD003F2D71 /* DBValidatorTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DBValidatorTests.h; sourceTree = "<group>"; };
2B5850C1173E37AD003F2D71 /* DBValidatorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DBValidatorTests.m; sourceTree = "<group>"; };
2B5850C3173E37AD003F2D71 /* DBValidatorTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DBValidatorTests-Prefix.pch"; sourceTree = "<group>"; };
+ 2B5850CA173E49EB003F2D71 /* DBStringLengthRuleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBStringLengthRuleTests.m; sourceTree = "<group>"; };
+ 2B5850CF173E4A62003F2D71 /* DBDummyClass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBDummyClass.h; sourceTree = "<group>"; };
+ 2B5850D0173E4A62003F2D71 /* DBDummyClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBDummyClass.m; sourceTree = "<group>"; };
65071146169D3EF700489DA0 /* DBValidationNumberRangeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBValidationNumberRangeRule.h; sourceTree = "<group>"; };
65071147169D3EF700489DA0 /* DBValidationNumberRangeRule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBValidationNumberRangeRule.m; sourceTree = "<group>"; };
65DA0CB5169CFC0200CE09AD /* DBValidator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DBValidator.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -112,7 +117,10 @@
children = (
2B5850C0173E37AD003F2D71 /* DBValidatorTests.h */,
2B5850C1173E37AD003F2D71 /* DBValidatorTests.m */,
+ 2B5850CA173E49EB003F2D71 /* DBStringLengthRuleTests.m */,
2B5850BB173E37AD003F2D71 /* Supporting Files */,
+ 2B5850CF173E4A62003F2D71 /* DBDummyClass.h */,
+ 2B5850D0173E4A62003F2D71 /* DBDummyClass.m */,
);
path = DBValidatorTests;
sourceTree = "<group>";
@@ -326,6 +334,8 @@
buildActionMask = 2147483647;
files = (
2B5850C2173E37AD003F2D71 /* DBValidatorTests.m in Sources */,
+ 2B5850CB173E49EB003F2D71 /* DBStringLengthRuleTests.m in Sources */,
+ 2B5850D1173E4A62003F2D71 /* DBDummyClass.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,16 @@
+//
+// DBDummyClass.h
+// DBValidator
+//
+// Created by Daniel Beard on 11/05/13.
+// Copyright (c) 2013 Daniel Beard. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface DBDummyClass : NSObject
+
+@property (nonatomic, copy) NSString *genericString;
+@property (nonatomic, strong) NSNumber *genericNumber;
+
+@end
@@ -0,0 +1,13 @@
+//
+// DBDummyClass.m
+// DBValidator
+//
+// Created by Daniel Beard on 11/05/13.
+// Copyright (c) 2013 Daniel Beard. All rights reserved.
+//
+
+#import "DBDummyClass.h"
+
+@implementation DBDummyClass
+
+@end
@@ -0,0 +1,107 @@
+//
+// DBStringLengthRuleTests.m
+// DBValidator
+//
+// Created by Daniel Beard on 11/05/13.
+// Copyright (c) 2013 Daniel Beard. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "DBDummyClass.h"
+#import "DBValidator.h"
+
+#define validation_message @"String must be between 5 and 10 characters"
+
+@interface DBStringLengthRuleTests : SenTestCase
+
+@end
+
+@implementation DBStringLengthRuleTests
+
+//Test expected case
+-(void) testValidatesProperly {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"Test1";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 0, @"Validation results should be empty");
+}
+
+//Test failing lower bound case
+-(void) testFailingLowerBoundCase {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"Test";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 1, @"Validation results should contain one object");
+}
+
+//Test failing upper bound case
+-(void) testFailingUpperBoundCase {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"Test1234567";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 1, @"Validation results should contain one object");
+}
+
+//Test lower boundary min length
+-(void) testLowerBoundaryMinLength {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"12345";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 0, @"Validation results should be empty");
+}
+
+//Test upper boundary max length
+-(void) testUpperBoundaryMaxLength {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"1234567890";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 0, @"Validation results should be empty");
+}
+
+//Test error message
+-(void) testErrorMessage {
+
+ DBDummyClass *object = [[DBDummyClass alloc] init];
+ DBValidationStringLengthRule *rule = [self stringLengthRuleForObject:object];
+ [object addValidationRule:rule];
+ object.genericString = @"11";
+
+ NSMutableArray *validationResults = [object validate];
+ STAssertTrue(validationResults.count == 1, @"Validation results should contain one object");
+ STAssertTrue([validationResults[0] isEqualToString:validation_message], @"Error message does not match expected value");
+}
+
+#pragma mark - Helper Methods
+
+-(DBValidationStringLengthRule*) stringLengthRuleForObject: (id) object {
+
+ DBValidationStringLengthRule *rule = [[DBValidationStringLengthRule alloc] initWithObject:object
+ keyPath:@"genericString"
+ minStringLength:5
+ maxStringLength:10
+ failureMessage:validation_message];
+ return rule;
+}
+
+
+@end
@@ -24,9 +24,4 @@ - (void)tearDown
[super tearDown];
}
-- (void)testExample
-{
- STFail(@"Unit tests are not implemented yet in DBValidatorTests");
-}
-
@end
View
@@ -6,7 +6,8 @@ General purpose validation framework for objective-c / iOS.
Supports adding validation rules to any keypath on an NSObject.
-http://danielbeard.wordpress.com
+* http://danielbeard.io
+* http://danielbeard.wordpress.com
Copyright (C) 2013 Daniel Beard

0 comments on commit cb51ec6

Please sign in to comment.