mockolo icon indicating copy to clipboard operation
mockolo copied to clipboard

Cont. on #146 Fail to generate mock with protocol inheritance

Open keithcml opened this issue 2 years ago • 4 comments

#146 @EspressoCup Sorry for disturbing you again.

keithcml avatar Nov 16 '21 02:11 keithcml

You'll need to pass a --mockfiles input option with paths to files that contain mocks of protocols that you inherit (which live in different modules). Please see test examples at https://github.com/uber/mockolo/blob/master/Tests/TestOverloads/OverloadTests.swift - testOverloadInParent, testOverloadInParentAndChild, or any tests that have the mockContent: parameter; this is used to pass in the file content for the --mockfiles option, and you should be able to see how it's used by stepping through the implementation with a debugger.

EspressoCup avatar Nov 16 '21 05:11 EspressoCup

thanks @EspressoCup . let me have a try first

keithcml avatar Nov 24 '21 14:11 keithcml

For anyone else looking for a solution you have to mock the parent in a separate call to mockolo, then pass the resulting mock into its subclass/implementor via --mockfiles

/// @mockable
protocol ProtocolB {
  func thisIsB()
}

/// @mockable
protocol ProtocolA: ProtocolB {

}
mockolo -srcs "ProtocolB.swift"  -d "MockProtocolB.swift" 
mockolo -srcs "ProtocolA.swift" --mockfiles "MockProtocolB.swift"  -d "Mock ProtocolB.swift"

RoryKelly avatar Dec 23 '21 13:12 RoryKelly

It works !

keithcml avatar Jan 17 '22 11:01 keithcml

It looks fine, so I will close it.

uhooi avatar Nov 23 '22 06:11 uhooi