Permalink
Browse files

Refactored tests and constructor to use single constructor & common s…

…etUp object
  • Loading branch information...
1 parent f57c0cf commit ee57e6dccee5782c2c79f25f7cb3e6ab9e6d89a5 @grosshei committed Nov 13, 2012
Showing with 24 additions and 8 deletions.
  1. +5 −1 BrowseOverflowTests/TopicTests.h
  2. +14 −4 BrowseOverflowTests/TopicTests.m
  3. +2 −1 Topic.h
  4. +3 −2 Topic.m
@@ -8,6 +8,10 @@
#import <SenTestingKit/SenTestingKit.h>
-@interface TopicTests : SenTestCase
+@class Topic;
+
+@interface TopicTests : SenTestCase{
+ Topic *topic;
+}
@end
@@ -11,14 +11,24 @@
@implementation TopicTests
+-(void)setUp{
+ topic = [[Topic alloc] initWithName:@"iPhone" tag:@"iphone"];
+}
+
+-(void)tearDown{
+ topic = nil;
+}
+
-(void) testThatTopicExists{
- Topic *newTopic = [[Topic alloc] init];
- STAssertNotNil(newTopic, @"Should be able to create a topic instance");
+ STAssertNotNil(topic, @"Should be able to create a topic instance");
}
-(void) testThatTopicCanBeNamed{
- Topic *namedTopic = [[Topic alloc] initWithName:@"iPhone"];
- STAssertEqualObjects(namedTopic.name, @"iPhone", @"The topic should have the name given");
+ STAssertEqualObjects(topic.name, @"iPhone", @"The topic should have the name given");
+}
+
+-(void) testThatTopicHasATag{
+ STAssertEqualObjects(topic.tag, @"iphone", @"Topics need to have tags");
}
@end
View
@@ -13,7 +13,8 @@
@property (readonly) NSString *name;
+@property (readonly) NSString *tag;
--(id)initWithName:(NSString *)newName;
+-(id)initWithName:(NSString *)newName tag:newTag;
@end
View
@@ -10,11 +10,12 @@
@implementation Topic
-@synthesize name;
+@synthesize name, tag;
--(id)initWithName:(NSString *)newName{
+-(id)initWithName:(NSString *)newName tag:newTag{
if(self = [super init]){
name = [newName copy];
+ tag = [newTag copy];
}
return self;
}

0 comments on commit ee57e6d

Please sign in to comment.