Closed ghost closed 9 years ago
After doing some extra research it turned out, that assemblies with run-time arguments written in Swift are working well within the code in Run environment. When we inject assembly itself into some object like in Typhoon Swift Example, then we can call method with run-time arguments without any problem.
So the reason why it all happened is incorrect creation of Assembly in Test environment. If I create assembly with Objective-C as it's shown in documentation, then test passes and everything works fine.
(ApplicationAssembly *)[TyphoonBlockComponentFactory factoryWithAssembly:[ApplicationAssembly assembly]];
So the only workaround I see for now, is to create some Objective-C helpers in Tests target that would only create Assemblies and then to use them in Swift tests.
TestAssembliesHelper.h
@interface TestAssembliesHelper : NSObject
+ (ApplicationAssembly *)applicationAssembly;
@end
TestAssembliesHelper.m
@implementation TestAssembliesHelper
+ (ApplicationAssembly *)applicationAssembly
{
return (ApplicationAssembly *)[TyphoonBlockComponentFactory factoryWithAssembly:[ApplicationAssembly assembly]];
}
@end
Somewhere in tests
let assembly = TestAssembliesHelper.applicationAssembly()
let requestCode = assembly.requestCodeApiGateway("1234567") as RequestCodeApiGateway
expect(requestCode).notTo(beNil())
expect(requestCode.phone).to(equal("1234567"))
Actually it's fine for me as it still works out-of-box in Run environment, but it would be interesting to know if there are any other solutions to this problem.
Hello Alexander,
Yes, it's problem in Swift to cast TyphoonBlockComponentFactory into TyphoonAssembly (because Swift hasn't ducky typing support), but we did our main API using duck typing, so it's impossible to create factory using swift. The only way to have factory in swift - create it in objc. In your project target you can inject factory using plist bootstraping, in test target - using objective-c workaround (similar to your).
We will fix that in future versions of typhoon (in typhoon 3.0) - requires rework main API..
Linked Issue: #253
Thank's a lot for your answer, and factory through plist - indeed! These solutions work for me especially when Typhoon 3.0 is coming :)
Hello,
I'm trying to implement assembly method that passes run-time argument into object constructor, but I'm stuck with several issues.
Here I'm getting Thread 1: signal SIGABRT when trying to cast with
as
.Real example:
RequestCodeApiGateway.swift
RequestCodeApiGatewayImpl.swift
ApplicationAssembly.swift
Somewhere in tests
P.S. I've also tried to implement assembly in Objective-C and to leave the rest in Swift, but I hadn't succeeded because of other 'Stopper' issues:
println(requestCode) results with next log:
po requestCode in debugger shows:
And exception log is here:
Could you please take a look and maybe there is something wrong in my implementation, or there is an issue within Typhoon's framework so it could be unveiled and fixed?
P.P.S. issue is reproduced on 2.3.2 version