 
         switch rule.response {
         case .NetworkResponse(let statusCode, let data):
-            let response = NSHTTPURLResponse(URL: rule.endpoint.URL, statusCode: statusCode, HTTPVersion: nil, headerFields: nil)
+            let response = NSHTTPURLResponse(URL: rule.URL, statusCode: statusCode, HTTPVersion: nil, headerFields: nil)
             completion(response: response, data: data, error: nil)
         case .NetworkError(let error):
             completion(response: nil, data: nil, error: error)

}

public class StubBackend: BackendType {
    private var stubs: [NSURL: StubRule]

    public init() {
        self.stubs = [:]
    }

    public func stubTarget(target: TargetType, behavior: StubBehavior, response: StubResponse) {
        let endpoint = target.endpoint

        self.stubs[endpoint.URL] = StubRule(endpoint: endpoint, behavior: behavior, response: response)
    }

    public func removeAllStubs() {
        self.stubs = [:]
    }

    public func request(request: NSURLRequest, completion: (response: NSHTTPURLResponse?, data: NSData?, error: NSError?) -> ()) -> Cancellable {
        guard let stubRule = self.stubs[request.URL!] else {
            fatalError("Request not stubbed yet.")
        }


}

public struct StubRule {
    let URL: NSURL
    let behavior: StubBehavior
    let response: StubResponse

    public init(URL: NSURL, behavior: StubBehavior, response: StubResponse) {
        self.URL = URL
        self.behavior = behavior
        self.response = response
    }
}

public struct StubAction: Equatable, Hashable {
    let URL: NSURL
    let method: Method

    public init(URL: NSURL, method: Method) {
        self.URL = URL
        self.method = method
    }

    public var hashValue: Int {
        return "\(self.method.rawValue) \(String(self.URL))".hashValue
    }
}

public func ==(lhs: StubAction, rhs: StubAction) -> Bool {
    return lhs.hashValue == rhs.hashValue
}

internal final class StubCancellableToken: Cancellable {
