Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSData+RCExtensionsTests: improved errors #2043

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ class NSDataExtensionsTests: TestCase {
extension NSDataExtensionsTests {

static func sampleReceiptData(receiptName: String) -> Data {
let receiptText = readFile(named: receiptName)
guard let receiptData = Data(base64Encoded: receiptText) else { fatalError("couldn't decode file") }
let receiptText = self.readFile(named: receiptName)
guard let receiptData = Data(base64Encoded: receiptText) else {
fatalError("Couldn't decode base64 file: \(receiptName).\(Self.fileExtension)")
}
return receiptData
}

static func readFile(named filename: String) -> String {
guard let pathString = Bundle(for: Self.self).path(forResource: filename, ofType: "txt") else {
fatalError("\(filename) not found")
guard let pathString = Bundle(for: Self.self).path(forResource: filename,
ofType: Self.fileExtension) else {
fatalError("File \(filename).\(Self.fileExtension) not found")
}
do {
return try String(contentsOfFile: pathString, encoding: String.Encoding.utf8)
return try String(contentsOfFile: pathString, encoding: .utf8)
} catch let error {
fatalError("couldn't read file named \(filename). Error: \(error.localizedDescription)")
fatalError("Couldn't read file named \(filename).\(Self.fileExtension).\n" +
"Error: \(error.localizedDescription)")
}
}

private static let fileExtension = "txt"

}