homebrew-core/Formula/mockolo.rb

59 lines
2.1 KiB
Ruby

class Mockolo < Formula
desc "Efficient Mock Generator for Swift"
homepage "https://github.com/uber/mockolo"
url "https://github.com/uber/mockolo/archive/1.6.3.tar.gz"
sha256 "87384b96d7e9c824c3debb4829c9f003005df946efaa8a4d3c6dbb3794c7efd0"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "137aae60dcd2bdadf64bc38ff1d0ca8f23cfbc40966e61dd12c1f195a2c9b30f"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "189657ede935330ef9f7a4884ec08b068594413f439f464a5566572bdad0842c"
sha256 cellar: :any_skip_relocation, monterey: "3aff5eea6fae248f9c5ffed4cafbfe98bcd65315314ac30ba37c0ae11ab82913"
sha256 cellar: :any_skip_relocation, big_sur: "43e30dec8ae85185b552f1fb3dc8e996def2ca3c669aaf573ced988eb10e0aac"
end
depends_on xcode: ["12.5", :build]
def install
system "swift", "build", "-c", "release", "--disable-sandbox"
bin.install ".build/release/mockolo"
end
test do
(testpath/"testfile.swift").write <<~EOS
/// @mockable
public protocol Foo {
var num: Int { get set }
func bar(arg: Float) -> String
}
EOS
system "#{bin}/mockolo", "-srcs", testpath/"testfile.swift", "-d", testpath/"GeneratedMocks.swift"
assert_predicate testpath/"GeneratedMocks.swift", :exist?
output = <<~EOS.gsub(/\s+/, "").strip
///
/// @Generated by Mockolo
///
public class FooMock: Foo {
public init() { }
public init(num: Int = 0) {
self.num = num
}
public private(set) var numSetCallCount = 0
public var num: Int = 0 { didSet { numSetCallCount += 1 } }
public private(set) var barCallCount = 0
public var barHandler: ((Float) -> (String))?
public func bar(arg: Float) -> String {
barCallCount += 1
if let barHandler = barHandler {
return barHandler(arg)
}
return ""
}
}
EOS
assert_equal output, shell_output("cat #{testpath/"GeneratedMocks.swift"}").gsub(/\s+/, "").strip
end
end