homebrew-core/Formula/mockolo.rb

57 lines
1.8 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.1.tar.gz"
sha256 "e6a701de847f20bb61f06c26d66c2ff9d492b44b82dcb76dff9e00f499cb1175"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "1d6affc1bcf5e25b214130b29c5b39ce563dce55c8ce878c4b37281b68f7ebf8"
sha256 cellar: :any_skip_relocation, big_sur: "164d14c4499086b3607ade66bc54e3daaf50a9b0e8983f1bc71454fe01d2a9ab"
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