title: Creating a Alamofire Response for a test
body: <p>I am using Alamofire in my iOS application for API calls.  I am trying to stub this data out in the tests, I have tried Mockingjay and OHHTTPStubs but neither work, so I am now trying to stub the response that I receive back.</p>
  
  <p>I need to create a Response with dummy data which I can pass to my other methods. Here is the initializer for the Response object in Alamofire:</p>
  
  <pre><code>public init(request: NSURLRequest?, response: NSHTTPURLResponse?, data: NSData?, result: Result&lt;Value, Error&gt;)
  </code></pre>
  
  <p>However I cannot work out how create this object, as I cannot create a Result.  Here is some of the result class from Alamofire:</p>
  
  <pre><code>public enum Result&lt;Value, Error: ErrorType&gt; {
      case Success(Value)
      case Failure(Error)
  
      /// Returns `true` if the result is a success, `false` otherwise.
      public var isSuccess: Bool {
          switch self {
          case .Success:
              return true
          case .Failure:
              return false
          }
      }
  
      /// Returns `true` if the result is a failure, `false` otherwise.
      public var isFailure: Bool {
          return !isSuccess
      }
  
      /// Returns the associated value if the result is a success, `nil` otherwise.
      public var value: Value? {
          switch self {
          case .Success(let value):
              return value
          case .Failure:
              return nil
          }
      }
  
      /// Returns the associated error value if the result is a failure, `nil` otherwise.
      public var error: Error? {
          switch self {
          case .Success:
              return nil
          case .Failure(let error):
              return error
          }
      }
  }
  </code></pre>
  
  <p>I can't seem to work out how to pass a result to the response object with a value in it, to represent an API response.</p>
  
  <p>I think I'm getting confused about enums, and how they can have variables in them also.</p>
  
  <p>Can anyone help me build a response?</p>
  
  <p>Thanks.</p>
  
  <p><strong>ANSWERED</strong></p>
  
  <p>Thanks for the answer...  Here is how you create the whole response with a json response</p>
  
  <pre><code>let london : NSDictionary = ["name" : "london", "latitude" : 23.00, "longitude" : 0.0, "id" : "london_gb"]
                  let paris : NSDictionary = ["name" : "paris", "latitude" : 30.00, "longitude" : -1.0, "id" : "paris_fr"]
                  let locations = NSArray(array: [london, paris])
                  let result = Result&lt;AnyObject, NSError&gt;.Success(locations)
  
                  var response = Response(request: NSURLRequest(), response: NSHTTPURLResponse(), data: NSData(), result: result)
  </code></pre>