Skip to content

Instantly share code, notes, and snippets.

@feighter09
Last active April 25, 2017 16:52
Show Gist options
  • Save feighter09/2d4e0bfbee1a3163d9b9f24900b319be to your computer and use it in GitHub Desktop.
Save feighter09/2d4e0bfbee1a3163d9b9f24900b319be to your computer and use it in GitHub Desktop.
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