Skip to content

0.20.0: Eagle Eye

Latest
Compare
Choose a tag to compare
@andrewchang-bird andrewchang-bird released this 29 Jan 01:50
· 3 commits to master since this release
0.20.0
6e0d473

Targets

Framework

  • Xcode 12.5+ / Swift 5.4+
  • iOS 9.0+, macOS 10.10+, tvOS 9.0+, watchOS 7.4+

Generator

  • macOS 10.15+

Migrating from 0.19

Mocking static members no longer requires referencing the staticMock property when resetting mocks or clearing stubs/invocations.

// Old
reset(BirdMock.staticMock)
reset(type(of: mock(Bird.self)).staticMock)

// New
reset(BirdMock.self)
reset(type(of: mock(Bird.self)))  // Preferred equivalent

New Features

Test async methods

You can now mock, stub, and verify async methods. Note that stubbing and verifying declarations requires the use of the await keyword due to limitations with Swift’s overload resolution. Thanks to @ailtonvivaz for implementing this feature (#277).

protocol Bird {
  func fetchMessage() async -> String
}
let bird = mock(Bird.self)
given(await bird.fetchMessage()).willReturn("Hello")
print(await bird.fetchMessage())  // Prints "Hello"
verify(await bird.fetchMessage()).wasCalled()

Verify initializers

This release adds the ability to verify how mocks are initialized in cases where the metatype is provided to the system under test. Thanks to @myihsan for implementing this feature (#280).

protocol Bird {
  init(name: String)
}
func createBird(type: Bird.Type) -> Bird {
  return type.init(name: "Ryan")
}
let bird = createBird(type(of: mock(Bird.self)))
verify(bird.initialize(name: "Ryan")).wasCalled()

Enhancements