@@ -278,6 +278,13 @@ final class JustSendingJSON: XCTestCase {
278278}
279279
280280final class JustSendingFiles : XCTestCase {
281+ private var elonPhotoURL : URL {
282+ let lastPathSegmentLength = #file. split ( separator: " / " ) . last!. count
283+ let parentLength = #file. count - lastPathSegmentLength
284+ let elonPhotoPath = String ( #file. prefix ( parentLength) ) + " elon.jpg "
285+ return URL ( fileURLWithPath: elonPhotoPath)
286+ }
287+
281288 func testNotIncludeMultipartHeaderForEmptyFiles( ) {
282289 let r = Just . post ( " http://httpbin.org/post " , files: [ : ] )
283290 XCTAssertNotNil ( r. json)
@@ -293,27 +300,18 @@ final class JustSendingFiles: XCTestCase {
293300 }
294301
295302 func testSendingAFileSpecifiedByURLWithoutMimetype( ) {
296- if let elonPhotoURL = Bundle ( for: JustSendingFiles . self)
297- . url ( forResource: " elon " , withExtension: " jpg " )
298- {
299- let r = Just . post ( " http://httpbin.org/post " ,
300- files: [ " elon " : . url( elonPhotoURL, nil ) ] )
301- XCTAssertNotNil ( r. json)
302- if let data = r. json as? [ String : Any ] {
303- XCTAssertNotNil ( data [ " files " ] )
304- if let files = data [ " files " ] as? [ String : String ] {
305- XCTAssertNotNil ( files [ " elon " ] )
306- }
303+ let r = Just . post ( " http://httpbin.org/post " ,
304+ files: [ " elon " : . url( elonPhotoURL, nil ) ] )
305+ XCTAssertNotNil ( r. json)
306+ if let data = r. json as? [ String : Any ] {
307+ XCTAssertNotNil ( data [ " files " ] )
308+ if let files = data [ " files " ] as? [ String : String ] {
309+ XCTAssertNotNil ( files [ " elon " ] )
307310 }
308- } else {
309- XCTFail ( " resource needed for this test can't be found " )
310311 }
311312 }
312313
313314 func testSendingAFileSpecifiedByURLWithMimetype( ) {
314- if let elonPhotoURL = Bundle ( for: JustSendingFiles . self)
315- . url ( forResource: " elon " , withExtension: " jpg " )
316- {
317315 let r = Just . post ( " http://httpbin.org/post " ,
318316 files: [ " elon " : . url( elonPhotoURL, " image/jpeg " ) ] )
319317 XCTAssertNotNil ( r. json)
@@ -323,9 +321,6 @@ final class JustSendingFiles: XCTestCase {
323321 XCTAssertNotNil ( files [ " elon " ] )
324322 }
325323 }
326- } else {
327- XCTFail ( " resource needed for this test can't be found " )
328- }
329324 }
330325
331326 func testSendingAFileSpecifiedByDataWithoutMimetype( ) {
0 commit comments