Implemented the "actions" property for the FileServiceSpy spy in the tests target to support tracking multiple actions.
This commit is contained in:
parent
a1ad391baa
commit
12151deea0
@ -39,8 +39,11 @@ struct FileServiceTests {
|
||||
try await service.createFolder(at: url)
|
||||
|
||||
// THEN
|
||||
#expect(spy.isCreateFolderCalled == true)
|
||||
#expect(spy.urlCalled == url)
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .folderCreated(url))
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someExistingFolder, .someExistingFile, .someRandomURL],
|
||||
@ -61,9 +64,8 @@ struct FileServiceTests {
|
||||
await #expect(throws: error) {
|
||||
try await service.createFolder(at: url)
|
||||
}
|
||||
|
||||
#expect(spy.isCreateFolderCalled == false)
|
||||
#expect(spy.urlCalled == nil)
|
||||
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||
@ -79,8 +81,11 @@ struct FileServiceTests {
|
||||
try await service.delete(at: url)
|
||||
|
||||
// THEN
|
||||
#expect(spy.isDeleteCalled == true)
|
||||
#expect(spy.urlCalled == url)
|
||||
#expect(spy.actions.count == 1)
|
||||
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .itemDeleted(url))
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someNewFolder, .someNewFile, .someRandomURL],
|
||||
@ -102,8 +107,7 @@ struct FileServiceTests {
|
||||
try await service.delete(at: url)
|
||||
}
|
||||
|
||||
#expect(spy.isDeleteCalled == false)
|
||||
#expect(spy.urlCalled == nil)
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someExistingFolder, .someExistingFile, .someNewFolder, .someNewFile],
|
||||
@ -125,8 +129,9 @@ struct FileServiceTests {
|
||||
// THEN
|
||||
#expect(result == outcome)
|
||||
|
||||
#expect(spy.isExistsAtCalled == true)
|
||||
#expect(spy.urlCalled == url)
|
||||
let action = try #require(spy.actions.last)
|
||||
|
||||
#expect(action == .itemExists(url))
|
||||
}
|
||||
|
||||
@Test(arguments: zip([URL.someRandomURL], [FileServiceError.urlNotFileURL]))
|
||||
@ -147,8 +152,7 @@ struct FileServiceTests {
|
||||
try await service.exists(at: url)
|
||||
}
|
||||
|
||||
#expect(spy.isExistsAtCalled == false)
|
||||
#expect(spy.urlCalled == nil)
|
||||
#expect(spy.actions.isEmpty == true)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,10 +6,7 @@ final class FileServiceSpy {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private(set) var isCreateFolderCalled: Bool = false
|
||||
private(set) var isDeleteCalled: Bool = false
|
||||
private(set) var isExistsAtCalled: Bool = false
|
||||
private(set) var urlCalled: URL?
|
||||
private(set) var actions: [Action] = []
|
||||
|
||||
}
|
||||
|
||||
@ -20,22 +17,29 @@ extension FileServiceSpy: FileServicing {
|
||||
get async { .someCurrentFolder }
|
||||
}
|
||||
|
||||
func createFolder(at url: URL) async throws(FileServiceError) {
|
||||
isCreateFolderCalled = true
|
||||
urlCalled = url
|
||||
func createFolder(at url: URL) async throws (FileServiceError) {
|
||||
actions.append(.folderCreated(url))
|
||||
}
|
||||
|
||||
func delete(at url: URL) async throws(FileServiceError) {
|
||||
isDeleteCalled = true
|
||||
urlCalled = url
|
||||
func delete(at url: URL) async throws (FileServiceError) {
|
||||
actions.append(.itemDeleted(url))
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func exists(at url: URL) async throws(FileServiceError) -> Bool {
|
||||
isExistsAtCalled = true
|
||||
urlCalled = url
|
||||
|
||||
func exists(at url: URL) async throws (FileServiceError) -> Bool {
|
||||
actions.append(.itemExists(url))
|
||||
|
||||
return .random()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Action
|
||||
|
||||
extension FileServiceSpy {
|
||||
enum Action: Equatable {
|
||||
case folderCreated(_ url: URL)
|
||||
case itemDeleted(_ url: URL)
|
||||
case itemExists(_ url: URL)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user