3

I am trying to set up the Typhoon framework with an example project and it works fine when I run the simulator but its giving me an error when I try to run tests. The error is the following:

NSInvalidArgumentException', reason: 'Class 'DI_Example.MyAssembly' is not a sub-class of TyphoonAssembly'

Now, I read here and here that this is caused by the Typhoon package being linked twice because of CocoaPods. So this is my Podfile and it doesn't seem that it should be linked it twice

platform :ios, '8.0'

target 'DI_Example', :exclusive => true do
    pod 'Typhoon', '~> 2.3' end

target 'DI_ExampleTests', :exclusive => true do end

inhibit_all_warnings!

Also when I change the tests target from applicaiton-style to logic-style everything seems to work fine (I am assuming because the package is not imported twice). Can anyone spot a problem with what I am doing?

It seems that the error is thrown before even hitting my test so I am guessing it has to do with linking the two targets

Here is my test (which is passing if I set the Host Application to None

var controller: HomeViewController!
override func setUp() {
    super.setUp()
    let ctrlAssembly = ControllersAssembly()
    let blAssembly = BusinessLogicAssembly()
    ctrlAssembly.blAssembly = blAssembly
    let factory = TyphoonBlockComponentFactory(assemblies: [blAssembly, ctrlAssembly])
    let configurer = TyphoonConfigPostProcessor()
    configurer.useResourceWithName("Info.plist")
    factory.attachPostProcessor(configurer)


    controller = factory.componentForKey("homeViewController") as HomeViewController
}

func testControllerTitle() {
    // Arrange

    // Act
    controller.viewDidLoad()

    // Assert
    println(controller.title)
    XCTAssertTrue(controller.title == "Root View", "Title is set")
}
Community
  • 1
  • 1
Adrian Hristov
  • 1,957
  • 2
  • 16
  • 22
  • 1
    You mentioned it doesn't "seem" like the Typhoon dependencies are linked twice. Can you verify by checking your test target's Build Phases tab? You should see the library linked under 'Link Binary With Libraries' – jervine10 Dec 16 '14 at 13:41
  • it says '0 items' for the test target and '1 item' for the app target which is the libPods.a one – Adrian Hristov Dec 16 '14 at 13:44
  • I am reusing the same **Pods-DI_Example.debug.xcconfig** in both targets' configuration but if I do not specify one for the test target it wouldn't find Typhoon files – Adrian Hristov Dec 16 '14 at 13:48
  • Hmm.. it is my understanding that Pods-DI_ExampleTests.xcconfig should have Typhoon in it based on the way your podfile is set up. Can you open the config and see if this is the case? – jervine10 Dec 16 '14 at 13:51
  • I do not understand exactly what it does but here it is GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Typhoon" OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/Typhoon" OTHER_LDFLAGS = -ObjC -l"Pods-DI_Example-Typhoon" OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS) PODS_ROOT = ${SRCROOT}/Pods – Adrian Hristov Dec 16 '14 at 13:56
  • So I noticed that I have all my classes (assemblies, controllers etc.) being members of both targets (which I set on purpose) but looking at Typhoon's Swift example they do not have their classes targeting the test target. Do you know how I can achieve this without an error being thrown that the classes are missing? – Adrian Hristov Dec 16 '14 at 14:15
  • My recommendation is to change the test target's configuration to point to the Pods-DI_ExampleTests.xcconfig. Then add the libPods-DI_ExampleTests.a library to the target in the 'Link Binary with Libraries' section. – jervine10 Dec 16 '14 at 14:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67021/discussion-between-jervine10-and-adrian-hristov). – jervine10 Dec 16 '14 at 14:16

1 Answers1

2

So I managed to resolve the issue. The problem was that because I did not have any dependencies on the test target I did not have Pods-PocketForecastTests.debug.xcconfig so in my project configuration I used the same config file as the app target which I guess causes it to be linked twice.

Adrian Hristov
  • 1,957
  • 2
  • 16
  • 22