Browse Source

Fixing AlamofireRequestDebugDescriptionTestCase on OS X

Mattt Thompson 11 years ago
parent
commit
894f840d8d
1 changed files with 22 additions and 9 deletions
  1. 22 9
      Tests/RequestTests.swift

+ 22 - 9
Tests/RequestTests.swift

@@ -90,15 +90,25 @@ class AlamofireRequestDescriptionTestCase: XCTestCase {
 }
 
 class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
-    private func cURLCommandComponents(request: Request) -> [String] {
-        return request.debugDescription.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).filter { $0 != "" && $0 != "\\" }
+    let manager = Alamofire.Manager(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
+
+    // MARK: -
+
+    override func setUp() {
+        manager.startRequestsImmediately = false
+
+        if let cookieStorage = manager.session.configuration.HTTPCookieStorage {
+            for cookie in cookieStorage.cookies ?? [] {
+                cookieStorage.deleteCookie(cookie as NSHTTPCookie)
+            }
+        }
     }
 
     // MARK: -
 
     func testGETRequestDebugDescription() {
         let URL = "http://httpbin.org/get"
-        let request = Alamofire.request(.GET, URL)
+        let request = manager.request(.GET, URL)
         let components = cURLCommandComponents(request)
 
         XCTAssert(components[0..<3] == ["$", "curl", "-i"], "components should be equal")
@@ -108,7 +118,7 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
 
     func testPOSTRequestDebugDescription() {
         let URL = "http://httpbin.org/post"
-        let request = Alamofire.request(.POST, URL)
+        let request = manager.request(.POST, URL)
         let components = cURLCommandComponents(request)
 
         XCTAssert(components[0..<3] == ["$", "curl", "-i"], "components should be equal")
@@ -118,7 +128,7 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
 
     func testPOSTRequestWithJSONParametersDebugDescription() {
         let URL = "http://httpbin.org/post"
-        let request = Alamofire.request(.POST, URL, parameters: ["foo": "bar"], encoding: .JSON)
+        let request = manager.request(.POST, URL, parameters: ["foo": "bar"], encoding: .JSON)
         let components = cURLCommandComponents(request)
 
         XCTAssert(components[0..<3] == ["$", "curl", "-i"], "components should be equal")
@@ -131,8 +141,6 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
     func testPOSTRequestWithCookieDebugDescription() {
         let URL = "http://httpbin.org/post"
 
-        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
-
         let properties = [
             NSHTTPCookieDomain: "httpbin.org",
             NSHTTPCookiePath: "/post",
@@ -140,9 +148,8 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
             NSHTTPCookieValue: "bar",
         ]
         let cookie = NSHTTPCookie(properties: properties)!
-        configuration.HTTPCookieStorage?.setCookie(cookie)
+        manager.session.configuration.HTTPCookieStorage?.setCookie(cookie)
 
-        let manager = Alamofire.Manager(configuration: configuration)
         let request = manager.request(.POST, URL)
         let components = cURLCommandComponents(request)
 
@@ -151,4 +158,10 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
         XCTAssert(components[5..<7] == ["-b", "\"foo=bar\""], "command should contain -b flag")
         XCTAssert(components.last! == "\"\(URL)\"", "URL component should be equal")
     }
+
+    // MARK: -
+
+    private func cURLCommandComponents(request: Request) -> [String] {
+        return request.debugDescription.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).filter { $0 != "" && $0 != "\\" }
+    }
 }