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 (suggestion):
I think this is very fine, I also think this is why modularization of codebases is a big :+1: - because we can keep these tests solid and out of our daily codebase.


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)
                    }
                })
            }
        }
    }
}