Skip to content

0.2

Compare
Choose a tag to compare
@felixvisee felixvisee released this 28 Jul 11:56
· 114 commits to master since this release

So, this is almost a complete rewrite, adding a few new features but more importantly fixing many pain points we encountered internally. Here is a summary of the changes:

Expectations

Argument<T: Equatable> and Interaction*<...> have been merged into Expectation<Value>, which no longer requires its value to be equatable. Instead, matching is now entirely closure-based and the framework ships with a handful of convenience functions, also for equatable types. Expectations can be nested!

let mock = Mock<(Int, Int, Int, NSURL)>()
mock.expect(matches((any(), equals(1), 2, matches { $0.absoluteString == "http://www.rheinfabrik.de" })))

Mocks

The usage of mocks has been changed to be more like in other frameworks: (1) set expectations, (2) record interactions, and (3) verify expectations and interactions. Recording interactions is no longer Argument based, which was rather confusing. Error messages are awesome 😅

mock.record(0, 0, 2, NSURL(string: "http://www.rheinfabrik.de")!)
mock.verify() // Expectation <(_, 1, 2, <func>)> does not match interaction <(0, 0, 2, http://www.rheinfabrik.de)>

Stubs

Besides simply returning a value, defining interaction-depdent behavior is now possible. Also, defining behavior now returns a disposable, enabling its removal.

let stub = Stub<(Int, Int), Int>()
let disposable = stub.on(matches((4, 3)), returnValue: 9)
stub.on(matches((any(), any()))) { $0.0 + $0.1 }
disposable.dispose()

stub.invoke(4, 3) // .Some(7)

Please check out the source and tests for further documentation.