         
     }
     
+    /// Creates a data task for a given request and calls the completion handler on a background queue.
     public func dataTask(request request: URLRequestEncodable, completion: (NSData?, NSURLResponse?, NSError?) -> Void) -> DataTask {
         requestSent(request)
         

}

extension MockResponse: MockableDataTaskResult {
    public func dataTaskResult(request: URLRequestEncodable) -> (NSData?, NSURLResponse?, NSError?) {
        guard let responseURL = url ?? request.urlRequestValue.URL else {
            return (nil, nil, Error.InvalidURL as NSError)


// MARK: - MockableResponse

/// Defined an interface for mocking data task result data for a given request.
public protocol MockableDataTaskResult {
    /**
     Returns data that will be passed to the data task's completion handler
     - parameter request: The request that the data task result is responding to.
     - returns: Data that will be passed to the completion handler of the task.
    */
    func dataTaskResult(request: URLRequestEncodable) -> (NSData?, NSURLResponse?, NSError?)
}

// MARK: - MockResponse

/// Encapsulates the meta and body data of a response.
public struct MockResponse {
    enum Error: ErrorType {
        case InvalidURL
    }
    
    /// HTTP status code.
    public let statusCode: Int
 
    /// Response body data
    public var data: NSData?
    
    /// Response URL
    public var url: NSURL?
    
    /// HTTP header fields
    public var headers: [String : String]?
    
    /// Version of the HTTP response as represented by the server. Typically this is represented as "HTTP/1.1".
    public var version: String?
    
    /// Create a mock response with a given status code.
    public init(statusCode: Int) {
        self.statusCode = statusCode
    }
    
    /// Create a mock response with a status code and response body data.
    public init(statusCode: Int, data: NSData) {
        self.init(statusCode: statusCode)
        self.data = data
    }
    
    /// Create a mocked response with a  JSON object to use as the stubbed response body data.
    public init(statusCode: Int, json: AnyObject) {
        self.init(statusCode: statusCode)
        self.data = try? NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions(rawValue: 0))
