Again available on AppStore https://itunes.apple.com/cz/app/rubicon/id1453837387
Swift parser + mock generator
Rubicon generates spys for protocol. Generating methods for parent protocol is not supported.
input:
protocol Car {
var name: String? { get }
var color: Int { get set }
func go()
func load(with stuff: Int, label: String) throws -> Int
func isFull() -> Bool
}
output:
class CarSpy: Car {
var name: String?
var color: Int
struct Load {
let stuff: Int
let label: String
}
var goCount = 0
var load = [Load]()
var isFullCount = 0
var isFullReturn: Bool
init(color: Int, isFullReturn: Bool) {
self.color = color
self.isFullReturn = isFullReturn
}
func go() {
goCount += 1
}
func load(with stuff: Int, label: String) {
let item = Load(stuff: stuff, label: label)
load.append(item)
}
func isFull() -> Bool {
isFullCount += 1
return isFullReturn
}
}
output:
class CarStub: Car {
var name: String?
var color: Int
var isFullReturn: Bool
init(color: Int, isFullReturn: Bool) {
self.color = color
self.isFullReturn = isFullReturn
}
func go() {
}
func load(with stuff: Int, label: String) {
}
func isFull() -> Bool {
return isFullReturn
}
}
output:
class CarDummy: Car {
var name: String? {
fatalError()
}
var color: Int {
get {
fatalError()
}
set {
fatalError()
}
}
func go() {
fatalError()
}
func load(with stuff: Int, label: String) {
fatalError()
}
func isFull() -> Bool {
fatalError()
}
}
let carSpy = CarSpy()
...
XCTAssertEqual(carSpy.goCount, 1)
XCTAssertEqual(carSpy.load.count, 1)
XCTAssertEqual(carSpy.load[0].stuff, 2)
XCTAssertEqual(carSpy.load[0].label, "name")
Rubicon cli can generate mocks for every protocol in folder. Script runs through every swift file and find every protocol definition. Result is printed at standard out.
example:
$ ./rubicon --spy .
--mocks path
- generates spies (deprecated)
--spy path
- generates spies
--stub path
- generates stubs
--dummy path
- generates dummies
Xcode extension can generate Spy for every or selected protocol
in current file. Spy can be written to source file or pasteboard.