Repository: Moya/Moya
File: Moya/MoyaTests/MoyaProviderIntegrationTests.swift (Swift)

Code before:
                    }
                    
                    it("returns some data for zen request") {
                        var message: String?
                        
                        let target: GitHub = .Zen
                        provider.request(target, completion: { (object, error) in
                            if let data = object as? NSData {
                                message = NSString(data: data, encoding: NSUTF8StringEncoding)
                            }
                        })
                        
                        let sampleData = target.sampleData as NSData
                        expect{message}.toEventuallyNot(beNil(), timeout: 1, pollInterval: 0.1)
                    }
                    
                    it("returns some data for user profile request") {
                        var response: NSDictionary?
                        
                        let target: GitHub = .UserProfile("ashfurrow")
                        provider.request(target, completion: { (object, error) in
                            if let data = object as? NSData {
                                response = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSDictionary
                            }
                        })
                        
                        let sampleData = target.sampleData as NSData
                        let sampleResponse: NSDictionary = NSJSONSerialization.JSONObjectWithData(sampleData, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
                        expect{response}.toEventuallyNot(beNil(), timeout: 1, pollInterval: 0.1)
                    }
                })
            }
        }
    }
}


Review comment (bug):
These are integration tests that actually hit the network (to ensure that Moya can, and does). I had one test failure because my home internet was being slow, so I figured bumping up to 10 seconds was prudent. 


Code after:
                    it("returns some data for zen request") {
                        var message: String?
                        
                        let target: GitHub = .Zen
                        provider.request(target, completion: { (object, error) in
                            if let data = object as? NSData {
                                message = NSString(data: data, encoding: NSUTF8StringEncoding)
                            }
                        })
                        
                        expect{message}.toEventuallyNot(beNil(), timeout: 10, pollInterval: 0.1)
                    }
                    
                    it("returns some data for user profile request") {
                        var response: NSDictionary?
                        
                        let target: GitHub = .UserProfile("ashfurrow")
                        provider.request(target, completion: { (object, error) in
                            if let data = object as? NSData {
                                response = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSDictionary
                            }
                        })
                        
                        let sampleData = target.sampleData as NSData
                        let sampleResponse: NSDictionary = NSJSONSerialization.JSONObjectWithData(sampleData, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
                        expect{response}.toEventuallyNot(beNil(), timeout: 10, pollInterval: 0.1)
                    }
                })
            }
        }
    }
}