Skip to content

Commit

Permalink
Refactored the download tests to DRY them up a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Sep 6, 2015
1 parent 4e633d6 commit 42ea00e
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Tests/DownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class DownloadResponseTestCase: BaseTestCase {
let searchPathDirectory: NSSearchPathDirectory = .CachesDirectory
let searchPathDomain: NSSearchPathDomainMask = .UserDomainMask

let cachesURL: NSURL = {
let cachesDirectory = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first!
let cachesURL = NSURL(fileURLWithPath: cachesDirectory, isDirectory: true)

return cachesURL
}()

var randomCachesFileURL: NSURL {
return cachesURL.URLByAppendingPathComponent("\(NSUUID().UUIDString).json")
}

func testDownloadRequest() {
// Given
let numberOfLines = 100
Expand Down Expand Up @@ -245,17 +256,11 @@ class DownloadResponseTestCase: BaseTestCase {

func testDownloadRequestWithParameters() {
// Given
let fileURL: NSURL = {
let cachesDirectory = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first!
let cachesURL = NSURL(fileURLWithPath: cachesDirectory, isDirectory: true)
let fileURL = cachesURL.URLByAppendingPathComponent("\(NSUUID().UUIDString).json")

return fileURL
}()

let fileURL = randomCachesFileURL
let URLString = "https://httpbin.org/get"
let parameters = ["foo": "bar"]
let destination: Request.DownloadFileDestination = { _, _ in fileURL }

let expectation = expectationWithDescription("Download request should download data to file: \(fileURL)")

var request: NSURLRequest?
Expand Down Expand Up @@ -293,17 +298,11 @@ class DownloadResponseTestCase: BaseTestCase {

func testDownloadRequestWithHeaders() {
// Given
let fileURL: NSURL = {
let cachesDirectory = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first!
let cachesURL = NSURL(fileURLWithPath: cachesDirectory, isDirectory: true)
let fileURL = cachesURL.URLByAppendingPathComponent("\(NSUUID().UUIDString).json")

return fileURL
}()

let fileURL = randomCachesFileURL
let URLString = "https://httpbin.org/get"
let headers = ["Authorization": "123456"]
let destination: Request.DownloadFileDestination = { _, _ in fileURL }

let expectation = expectationWithDescription("Download request should download data to file: \(fileURL)")

var request: NSURLRequest?
Expand Down

0 comments on commit 42ea00e

Please sign in to comment.