Permalink
Browse files

Added JSObjectionInjector#injectDependencies method which closes issue

  • Loading branch information...
1 parent 85cd084 commit 21a0a282b1ffefdd00a7c583b05f6e636893f786 @dewind dewind committed Dec 1, 2012
Showing with 19 additions and 1 deletion.
  1. +1 −0 Source/JSObjectionInjector.h
  2. +3 −1 Source/JSObjectionInjector.m
  3. +15 −0 Specs/BasicUsageSpecs.m
View
1 Source/JSObjectionInjector.h
@@ -20,5 +20,6 @@
- (id)withoutModuleOfType:(Class)moduleClass;
- (id)withoutModuleOfTypes:(Class)first, ... NS_REQUIRES_NIL_TERMINATION;
- (id)withoutModuleCollection:(NSArray *)moduleClasses;
+- (void)injectDependencies:(id)object;
- (id)objectForKeyedSubscript: (id)key;
@end
View
4 Source/JSObjectionInjector.m
@@ -186,11 +186,13 @@ - (id)withoutModuleCollection:(NSArray *)moduleClasses {
}
}
}
- NSLog(@"Hello: %@", remainingModules);
return [[[self class] alloc] initWithContext:_globalContext andModules:remainingModules];
}
+- (void)injectDependencies:(id)object {
+ JSObjectionUtils.injectDependenciesIntoProperties(self, [object class], object);
+}
#pragma mark - Private
View
15 Specs/BasicUsageSpecs.m
@@ -33,6 +33,21 @@
assertThat(car.brakes, is(instanceOf([Brakes class])));
});
+it(@"will inject dependencies into properties of an existing instance", ^{
+ Car *car = [[[Car alloc] init] autorelease];
+
+ assertThat(car.engine, is(nilValue()));
+ assertThat(car.brakes, is(nilValue()));
+
+ [[JSObjection defaultInjector] injectDependencies:car];
+
+ assertThat(car.engine, isNot(nilValue()));
+ assertThat(car.engine, is(instanceOf([Engine class])));
+
+ assertThat(car.brakes, isNot(nilValue()));
+ assertThat(car.brakes, is(instanceOf([Brakes class])));
+});
+
it(@"defaults to returning a new instance", ^{
id thomas = [[JSObjection defaultInjector] getObject:[Engine class]];
id gordan = [[JSObjection defaultInjector] getObject:[Engine class]];

0 comments on commit 21a0a28

Please sign in to comment.