Skip to content

Commit

Permalink
haveRecordedCalls
Browse files Browse the repository at this point in the history
  • Loading branch information
NikSativa committed Apr 7, 2023
1 parent b06e99e commit 9637f6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"state" : {
"revision" : "35f9e770f54ce62dd8526470f14c6e137cef3eea",
"version" : "2.1.1"
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00",
"version" : "2.1.2"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688",
"version" : "2.1.0"
"revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b",
"version" : "2.1.2"
}
}
],
Expand Down
24 changes: 12 additions & 12 deletions Source/Matcher/XCTAssertHaveRecordedCalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import XCTest
public func XCTAssertHaveRecordedCalls(_ spyable: some Spyable,
file: StaticString = #filePath,
line: UInt = #line) {
XCTAssertTrue(!spyable._callsDictionary.values.isEmpty,
descriptionOfActual(count: spyable._callsDictionary.values.count),
XCTAssertTrue(spyable.haveRecordedCalls,
descriptionOfActual(count: spyable.recordedCallsCount),
file: file,
line: line)
}
Expand All @@ -21,10 +21,10 @@ public func XCTAssertHaveRecordedCalls(_ spyable: some Spyable,
public func XCTAssertHaveNoRecordedCalls(_ spyable: some Spyable,
file: StaticString = #filePath,
line: UInt = #line) {
XCTAssertTrue(spyable._callsDictionary.values.isEmpty,
descriptionOfActual(count: spyable._callsDictionary.values.count),
file: file,
line: line)
XCTAssertFalse(spyable.haveRecordedCalls,
descriptionOfActual(count: spyable.recordedCallsCount),
file: file,
line: line)
}

/// Matcher used to determine if at least one call has been made.
Expand All @@ -34,8 +34,8 @@ public func XCTAssertHaveNoRecordedCalls(_ spyable: some Spyable,
public func XCTAssertHaveRecordedCalls(_ spyable: (some Spyable).Type,
file: StaticString = #filePath,
line: UInt = #line) {
XCTAssertTrue(!spyable._callsDictionary.values.isEmpty,
descriptionOfActual(count: spyable._callsDictionary.values.count),
XCTAssertTrue(spyable.haveRecordedCalls,
descriptionOfActual(count: spyable.recordedCallsCount),
file: file,
line: line)
}
Expand All @@ -47,10 +47,10 @@ public func XCTAssertHaveRecordedCalls(_ spyable: (some Spyable).Type,
public func XCTAssertHaveNoRecordedCalls(_ spyable: (some Spyable).Type,
file: StaticString = #filePath,
line: UInt = #line) {
XCTAssertTrue(spyable._callsDictionary.values.isEmpty,
descriptionOfActual(count: spyable._callsDictionary.values.count),
file: file,
line: line)
XCTAssertFalse(spyable.haveRecordedCalls,
descriptionOfActual(count: spyable.recordedCallsCount),
file: file,
line: line)
}

// MARK: - Private Helpers
Expand Down
20 changes: 18 additions & 2 deletions Source/Spy/Spyable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private var callsMapTable: NSMapTable<AnyObject, SpryDictionary<RecordedCall>> =
public extension Spyable {
// MARK: Instance

internal var _callsDictionary: SpryDictionary<RecordedCall> {
private var _callsDictionary: SpryDictionary<RecordedCall> {
guard let callsDict = callsMapTable.object(forKey: self) else {
let callsDict = SpryDictionary<RecordedCall>()
callsMapTable.setObject(callsDict, forKey: self)
Expand All @@ -18,6 +18,14 @@ public extension Spyable {
return callsDict
}

var haveRecordedCalls: Bool {
return !_callsDictionary.values.isEmpty
}

var recordedCallsCount: Int {
return _callsDictionary.values.count
}

func recordCall(functionName: String = #function, arguments: Any?..., file: String = #file, line: Int = #line) {
functionName.validateArguments(arguments)

Expand Down Expand Up @@ -51,7 +59,7 @@ public extension Spyable {

// MARK: Static

internal static var _callsDictionary: SpryDictionary<RecordedCall> {
private static var _callsDictionary: SpryDictionary<RecordedCall> {
guard let callsDict = callsMapTable.object(forKey: self) else {
let callsDict = SpryDictionary<RecordedCall>()
callsMapTable.setObject(callsDict, forKey: self)
Expand All @@ -61,6 +69,14 @@ public extension Spyable {
return callsDict
}

static var haveRecordedCalls: Bool {
return !_callsDictionary.values.isEmpty
}

static var recordedCallsCount: Int {
return _callsDictionary.values.count
}

static func recordCall(functionName: String = #function, arguments: Any?..., file: String = #file, line: Int = #line) {
functionName.validateArguments(arguments)

Expand Down

0 comments on commit 9637f6b

Please sign in to comment.