Skip to content

Instantly share code, notes, and snippets.

@carlos4242
Created February 16, 2017 18:27
Show Gist options
  • Save carlos4242/3409e0762bfaa7b4223e5252e18642bd to your computer and use it in GitHub Desktop.
Save carlos4242/3409e0762bfaa7b4223e5252e18642bd to your computer and use it in GitHub Desktop.
using BDD to test my RxSwift enabled service, how to stop a variable emitting a value when first bound
context("get messages") {
var messagesReceived: [Message]?
var parameterVariable = Variable<GetMessageParams>?((nil,nil,nil,nil))
beforeEach {
MessagesService.observableService(parametersObservable: parameterVariable.asObservable())
{ (service: MessagesService, params: GetMessageParams, callback: @escaping ([Message]?)->Void) in
service.getMessages(params: params) { messages in
callback(messages)
}
}.subscribe(onNext:{ messages in
messagesReceived = messages
}).addDisposableTo(disposeBag)
if let test = test, let wang = wang, let walk = walk {
test.addMock(with: "/profile/\(wang.Id)/invite/\(walk.Id)/search-profiles", method: .post, reply: .success(statusCode: 200, body: try! loadSampleJson(jsonFilename: "searchResults")))
}
}
it("should get a list of messages on all message boxes") {
typealias GetMessageParams = MessagesService.GetMessageParams
guard let disposeBag = disposeBag else {
expect(false).to(beTrue(), description: "preconditions failed")
return
}
waitUntil { done in
parameterVariable.value = (nil,nil,nil,nil)
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment