Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 42 lines (32 sloc) 1.651 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#import "SpecHelper.h"
#import "InitializerFixtures.h"

SPEC_BEGIN(InitializerSpecs)
__block JSObjectionInjector *injector = nil;

beforeEach(^{
    injector = [JSObjection createInjector];
});

it(@"instantiates the object with the default initializer arguments", ^{
    ViewController *controller = [injector getObject:[ViewController class]];
    
    [[controller.nibName should] equal:@"MyNib"];
    assertThat(controller.bundle, nilValue());
    [[controller.car should] beMemberOfClass:[Car class]];
});

it(@"will override the default arguments if arguments are passed to the injector", ^{
    ViewController *controller = [injector getObjectWithArgs:[ViewController class], @"AnotherNib", @"pretendBundle", nil];
    
    [[controller.nibName should] equal:@"AnotherNib"];
    [[controller.bundle should] equal:@"pretendBundle"];
    [[controller.car should] beMemberOfClass:[Car class]];
});

it(@"is OK to register an object with an initializer without any default arguments", ^{
    ConfigurableCar *car = [injector getObjectWithArgs:[ConfigurableCar class], @"Passat", [NSNumber numberWithInt:200], [NSNumber numberWithInt:2002], nil];
    
    [[car.horsePower should] equal:[NSNumber numberWithInt:200]];
    [[car.model should] equal:@"Passat"];
    [[car.year should] equal:[NSNumber numberWithInt:2002]];
    [[car.engine should] beMemberOfClass:[Engine class]];
});

it(@"raises an exception if the initializer is not valid", ^{
   [[theBlock(^{
       [injector getObject:[BadInitializer class]];
   }) should] raiseWithReason:@"Could not find initializer 'initWithNonExistentInitializer' on BadInitializer"];
});

SPEC_END
Something went wrong with that request. Please try again.