Skip to content

Commit 2269053

Browse files
Move custom logic from FileSystem mock to tests (#591)
1 parent 02bef62 commit 2269053

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Tests/NodesXcodeTemplatesGeneratorTests/Support/FileSystemMock.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ internal final class FileSystemMock: FileSystem {
3131
}
3232

3333
internal func copyItem(at fromURL: URL, to toURL: URL) throws {
34-
let path: String = fromURL.path.replacingOccurrences(of: "/Contents/Resources", with: "")
35-
let bundle: String = "Nodes_NodesXcodeTemplatesGenerator"
36-
copies.append((from: path.components(separatedBy: bundle).last!, to: toURL.path))
34+
copies.append((from: fromURL.path, to: toURL.path))
3735
}
3836

3937
internal func removeItem(at url: URL) throws {

Tests/NodesXcodeTemplatesGeneratorTests/XcodeTemplatesTests.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class XcodeTemplatesTests: XCTestCase {
1515
writes.forEach { assertSnapshot(of: $0.contents, as: .lines, named: "Contents.\(name(from: $0.path))") }
1616
assertSnapshot(of: writes.map { (path: $0.path, atomically: $0.atomically) }, as: .dump, named: "Writes")
1717
assertSnapshot(of: fileSystem.directories, as: .dump, named: "Directories")
18-
assertSnapshot(of: fileSystem.copies, as: .dump, named: "Copies")
18+
assertSnapshot(of: sanitize(fileSystem.copies), as: .dump, named: "Copies")
1919
assertSnapshot(of: fileSystem.deletions, as: .dump, named: "Deletions")
2020
}
2121

@@ -28,7 +28,7 @@ final class XcodeTemplatesTests: XCTestCase {
2828
writes.forEach { assertSnapshot(of: $0.contents, as: .lines, named: "Contents.\(name(from: $0.path))") }
2929
assertSnapshot(of: writes.map { (path: $0.path, atomically: $0.atomically) }, as: .dump, named: "Writes")
3030
assertSnapshot(of: fileSystem.directories, as: .dump, named: "Directories")
31-
assertSnapshot(of: fileSystem.copies, as: .dump, named: "Copies")
31+
assertSnapshot(of: sanitize(fileSystem.copies), as: .dump, named: "Copies")
3232
assertSnapshot(of: fileSystem.deletions, as: .dump, named: "Deletions")
3333
}
3434

@@ -41,6 +41,15 @@ final class XcodeTemplatesTests: XCTestCase {
4141
.replacingOccurrences(of: [".xctemplate", "___FILEBASENAME___", ".swift", ".plist"], with: "")
4242
}
4343

44+
private func sanitize(_ copies: [(from: String, to: String)]) -> [(from: String, to: String)] {
45+
// swiftlint:disable:next identifier_name
46+
copies.map { from, to in
47+
let from: String = from.replacingOccurrences(of: "/Contents/Resources", with: "")
48+
let bundle: String = "Nodes_NodesXcodeTemplatesGenerator"
49+
return (from: from.components(separatedBy: bundle).last!, to: to)
50+
}
51+
}
52+
4453
private func givenConfig() -> Config {
4554
var config: Config = .init()
4655
config.uiFrameworks = [

0 commit comments

Comments
 (0)