Skip to content

Instantly share code, notes, and snippets.

Avatar

Chelsea Troy chelseatroy

View GitHub Profile
View ExampleViewControllerTest.swift
func testNavigateToView_loadsView() {
let controller = ExampleViewController.loadFromStoryboard()
assertThat(controller.view, present())
UIWindow.present(viewController: controller) { () in
assertThat(controller.someTextLabel.text, presentAnd(equalTo("Why hello there!")))
}
}
@chelseatroy
chelseatroy / ExampleViewController.swift
Last active Sep 7, 2016
ViewController Dependency Injection
View ExampleViewController.swift
public class ExampleViewController: UIViewController {
var dependableService: DependableService
@IBOutlet var someTextLabel: UITextLabel!
class func loadFromStoryboard(
dependableService: DependableService) -> ExampleViewController {
let controller = UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
.instantiateViewControllerWithIdentifier("ExampleViewController")
as! ExampleViewController
@chelseatroy
chelseatroy / ExampleViewControllerTest.swift
Created Sep 7, 2016
View Controller Dependency Injection Test
View ExampleViewControllerTest.swift
class ExampleViewControllerTest: XCTestCase {
class FakeDependableService: DependableService {
var lastRequestParameter: String?
var stubbedResponse: DependableResponse?
init() {
super.init()
self.lastRequestParameter = ""
self.stubbedResponse = nil
@chelseatroy
chelseatroy / AppEnvironment.swift
Created Sep 7, 2016
View Controller Dependency Injection App Environment
View AppEnvironment.swift
class AppEnviroment: NSObject {
static let sharedEnvironment = AppEnviroment()
let dependableService:DependableService
override init() {
self.dependableService = DependableService()
super.init()
View CandiesMasterDetailFeature.swift
import XCTest
import Hamcrest
import PactConsumerSwift
class CandiesMasterDetailFeature: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
View CandiesMasterDetailFeature.swift
import XCTest
import Hamcrest
import PactConsumerSwift
class CandiesMasterDetailFeature: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false //So the moment that an assertion in the test fails, we will not continue with the test
View ExampleViewControllerTest.swift
import XCTest
import Hamcrest
@testable import MyExampleApp
class ExampleViewControllerTest: XCTestCase {
...
func testNavigatesToOtherScreen() {
View ExampleViewController.swift
class ExampleViewController: UIViewController {
...
@IBAction func didTapButtonToGoToOtherViewController(sender: AnyObject) {
self.performSegueWithIdentifier("otherViewControllerSegue", sender: nil)
}
}
@chelseatroy
chelseatroy / ExampleViewController.swift
Created Jan 26, 2017
Load from Storyboard iOS Example
View ExampleViewController.swift
import UIKit
class ExampleViewController: UIViewController {
class func loadFromStoryboard(exampleService: ExampleService) -> ExampleViewController {
let exampleViewController:ExampleViewController =
UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
.instantiateViewControllerWithIdentifier("ExampleViewController")
as! ExampleViewController
@chelseatroy
chelseatroy / ExampleViewControllerTest.swift
Last active Jan 27, 2017
Load from Storyboard Example iOS
View ExampleViewControllerTest.swift
import XCTest
import Hamcrest
import FutureKit
@testable import MyExampleApp
class ExampleViewControllerTest: XCTestCase {
...