Skip to content

Commit

Permalink
Merge pull request #62 from raptorxcz/feature/stub-naming
Browse files Browse the repository at this point in the history
Add option for custom stub naming
  • Loading branch information
raptorxcz authored Mar 26, 2024
2 parents 41e0af3 + da7677d commit c07023b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Rubicon/Generator/StubGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ final class StubGenerator {
self.initGenerator = initGenerator
}

func generate(from protocolType: ProtocolDeclaration) -> String {
func generate(from protocolType: ProtocolDeclaration, stubSuffix: String = "Stub") -> String {
let content = generateBody(from: protocolType)
return protocolGenerator.makeProtocol(
from: protocolType,
stub: "Stub",
stub: stubSuffix,
content: content
).joined(separator: "\n") + "\n"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Rubicon/Integration/Rubicon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class Rubicon {
let generator = makeStubGenerator(accessLevel: accessLevel, indentStep: indentStep)
do {
let protocols = try parser.parse(text: code)
return protocols.map(generator.generate(from:))
return protocols.map { generator.generate(from: $0) }
} catch {
return []
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/RubiconTests/Generator/StubGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ final class StubGeneratorTests: XCTestCase {
XCTAssertEqual(result, "result\n")
}

func test_givenEmptyProtocolWithCustomSuffix_whenGenerate_thenGenerateCode() {
let result = sut.generate(from: .makeStub(), stubSuffix: "Mock")

XCTAssertEqual(protocolGeneratorSpy.makeProtocol.first?.stub, "Mock")
}

func test_givenProtocolWithVariable_whenGenerate_thenGenerateStub() {
let protocolDeclaration = ProtocolDeclaration.makeStub(variables: [.makeStub()])

Expand Down

0 comments on commit c07023b

Please sign in to comment.