homebrew-core/Formula/mockolo.rb

60 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.7.0.tar.gz"
sha256 "b36c49d835895b643e631c5cba3c9048f0628f68d37c5adf739a30de93677304"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "fd3fa5acd3f6579f3fc968f4bec3ee352e02313534ee9e80ae34dc9140fea240"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "8e436ecc136b7f9a66327c93090fb31345392dac61ba5a1a1cc6155a05c103bb"
sha256 cellar: :any_skip_relocation, monterey: "68b348c545803f8e20294fee9882754bc99e6e7890248db34df255f522dad066"
sha256 cellar: :any_skip_relocation, big_sur: "fa228d10c41c6d10da3d529fbc65b64d122340528e2ad712033ebacf533f0786"
end
depends_on xcode: ["12.5", :build]
depends_on :macos # depends on os.signpost, which is macOS-only.
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