Skip to content

Instantly share code, notes, and snippets.

@feighter09

feighter09/spec.swift

Last active Apr 25, 2017
Embed
What would you like to do?
override func spec()
{
var subject: UIViewController!, viewModel: ViewModel!
beforeEach { (subject, viewModel) = self.newSubject }
context("once the view has loaded") {
beforeEach { subject.loadViewIfNeeded() }
describe("events sent to view model") {
context("when selection changes") {
beforeEach { subject.pickerView.selectedIndex = 1 }
it("sets view model selected index") {
expext(viewModel.selectedIndex).to(equal(1))
}
}
context("when the button is tapped") {
beforeEach { subject.button.tap() }
it("calls ViewModel.buttonTapHandler") {
expect(viewModel.buttonTapHandlerCalled).to(beTrue())
}
}
}
describe("updates recieved from view model") {
context("when phone number changes") {
beforeEach { viewModel.phoneNumber.value = "(555) 867-5309" }
it("updates the label") {
expect(subject.phoneNumberLabel.text).toEventually(equal("(555) 867-5309"))
}
}
// #1
context("when the location changes") {
beforeEach { viewModel.location.value = Location.NYC }
it("updates latitude label") {
expect(subject.latituteLabel.text).to(equal(Location.NYC.latitude))
}
it("updates longitude label") {
expect(subject.longitudeLabel.text).to(equal(Location.NYC.longitude))
}
}
// #2
it("binds location to appropriate labels") {
viewModel.location.value = Location.NYC
expect(subject.latituteLabel.text).to(equal(Location.NYC.latitude))
expect(subject.longitudeLabel.text).to(equal(Location.NYC.longitude))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.