Skip to content

Commit

Permalink
Improve partial class mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewchang-bird committed Aug 5, 2021
1 parent 606799a commit 4e0ead8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/MockingbirdTestsHost/MinimalTestTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ protocol MinimalProtocol {

class MinimalClass {
var property: String = "super"
func method(value: String) -> String { return "super-" + value }
func method(value: String) -> String { return "\(value)-\(property)" }
}
15 changes: 13 additions & 2 deletions Tests/MockingbirdTests/Framework/PartialMockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class PartialMockTests: BaseTestCase {
}
}

class SelfReferencingImplementer: MinimalProtocol {
var property: String = "foobar"
func method(value: String) -> String {
return property
}
}

class UnrelatedType {}

override func setUpWithError() throws {
Expand Down Expand Up @@ -108,13 +115,17 @@ class PartialMockTests: BaseTestCase {
}

func testForwardMethodToSuperclass() throws {
given(classMock.property).willReturn("world")
given(classMock.method(value: any())).willForwardToSuper()
XCTAssertEqual(classMock.method(value: "hello"), "super-hello")
XCTAssertEqual(classMock.method(value: "hello"), "hello-world")
verify(classMock.property).wasCalled()
verify(classMock.method(value: "hello")).wasCalled()
}
func testForwardMethodToSuperclass_stubbingOperator() throws {
given(classMock.property) ~> "world"
given(classMock.method(value: any())) ~> forwardToSuper()
XCTAssertEqual(classMock.method(value: "hello"), "super-hello")
XCTAssertEqual(classMock.method(value: "hello"), "hello-world")
verify(classMock.property).wasCalled()
verify(classMock.method(value: "hello")).wasCalled()
}

Expand Down

0 comments on commit 4e0ead8

Please sign in to comment.