Repository: Moya/Moya
File: Demo/DemoTests/MoyaProviderSpec.swift (Swift)

Code before:
                    }
                    
                    it("returns stubbed data for user profile request") {
                        var message: String?
                        
                        let target: GitHub = .UserProfile("ashfurrow")
                        provider.request(target, completion: { (data, statusCode, response, error) in
                            if let data = data {
                                message = NSString(data: data, encoding: NSUTF8StringEncoding)
                            }
                        })
                        
                        let sampleData = target.sampleData as NSData
                        expect(message).to(equal(NSString(data: sampleData, encoding: NSUTF8StringEncoding)))
                    }
                    
                    it("returns equivalent Endpoint instances for the same target") {
                        let target: GitHub = .Zen
                        
                        let endpoint1 = provider.endpoint(target, method: Moya.DefaultMethod(), parameters: Moya.DefaultParameters())
                        let endpoint2 = provider.endpoint(target, method: Moya.DefaultMethod(), parameters: Moya.DefaultParameters())
                        expect(endpoint1).to(equal(endpoint2))
                    }
                })
                
                describe("a provider with a custom endpoint resolver", { () -> () in
                    var provider: MoyaProvider<GitHub>!
                    var executed = false
                    let newSampleResponse = "New Sample Response"
                    
                    beforeEach {
                        executed = false
                        let endpointResolution = { (endpoint: Endpoint<GitHub>) -> (NSURLRequest) in
                            executed = true
                            return endpoint.urlRequest
                        }
                        provider = MoyaProvider(endpointsClosure: endpointsClosure, endpointResolver: endpointResolution, stubResponses: true)
                    }
                    
                    it("executes the endpoint resolver") {
                        let target: GitHub = .Zen
                        provider.request(target, completion: { (data, statusCode, response, error) in })
                        
                        let sampleData = target.sampleData as NSData
                        expect(executed).to(beTruthy())
                    }
                })
                
                describe("a reactive provider", { () -> () in
                    var provider: ReactiveMoyaProvider<GitHub>!
                    beforeEach {

Review comment (suggestion):
Think I might move to `waitUntil` for all necessarily asynchronous tests, instead of `toEventually`.


Code after:
                    }
                    
                    it("returns stubbed data for user profile request") {
                        var message: String?
                        
                        let target: GitHub = .UserProfile("ashfurrow")
                        provider.request(target, completion: { (data, statusCode, response, error) in
                            if let data = data {
                                message = NSString(data: data, encoding: NSUTF8StringEncoding)
                            }
                        })
                        
                        let sampleData = target.sampleData as NSData
                        expect(message).to(equal(NSString(data: sampleData, encoding: NSUTF8StringEncoding)))
                    }
                    
                    it("returns equivalent Endpoint instances for the same target") {
                        let target: GitHub = .Zen
                        
                        let endpoint1 = provider.endpoint(target, method: Moya.DefaultMethod(), parameters: Moya.DefaultParameters())
                        let endpoint2 = provider.endpoint(target, method: Moya.DefaultMethod(), parameters: Moya.DefaultParameters())
                        expect(endpoint1).to(equal(endpoint2))
                    }
                })

                it("delays execution when appropriate") {
                    let closure = { (target: GitHub) -> (Moya.StubbedBehavior) in
                        return .Delayed(seconds: 2)
                    }

                    let provider = MoyaProvider(endpointsClosure: endpointsClosure, stubResponses: true, stubBehavior: closure)

                    let startDate = NSDate()
                    var endDate: NSDate?
                    let target: GitHub = .Zen
                    waitUntil(timeout: 3){ done in
                        provider.request(target, completion: { (data, statusCode, response, error) in
                            endDate = NSDate()
                            done()
                        })
                    }

                    expect{
                        return endDate?.timeIntervalSinceDate(startDate)
                    }.to( beGreaterThanOrEqualTo(NSTimeInterval(2)) )
                }

                describe("a provider with a custom endpoint resolver", { () -> () in
                    var provider: MoyaProvider<GitHub>!
                    var executed = false
                    let newSampleResponse = "New Sample Response"