Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / ExampleViewControllerTest.swift
Last active September 7, 2016 13:03
View Controller Unit Test
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 September 7, 2016 17:17
ViewController Dependency Injection
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 September 7, 2016 16:49
View Controller Dependency Injection Test
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 September 7, 2016 17:15
View Controller Dependency Injection App Environment
class AppEnviroment: NSObject {
static let sharedEnvironment = AppEnviroment()
let dependableService:DependableService
override init() {
self.dependableService = DependableService()
super.init()
@chelseatroy
chelseatroy / CandiesMasterDetailFeature.swift
Created September 8, 2016 02:49
Example iOS Feature Test
import XCTest
import Hamcrest
import PactConsumerSwift
class CandiesMasterDetailFeature: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
@chelseatroy
chelseatroy / CandiesMasterDetailFeature.swift
Last active September 8, 2016 22:34
Annotated iOS Feature Test
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
@chelseatroy
chelseatroy / ExampleViewControllerTest.swift
Last active January 25, 2017 02:01
Test Screen Transition iOS
import XCTest
import Hamcrest
@testable import MyExampleApp
class ExampleViewControllerTest: XCTestCase {
...
func testNavigatesToOtherScreen() {
@chelseatroy
chelseatroy / ExampleViewController.swift
Created January 25, 2017 02:04
Screen Transition iOS
class ExampleViewController: UIViewController {
...
@IBAction func didTapButtonToGoToOtherViewController(sender: AnyObject) {
self.performSegueWithIdentifier("otherViewControllerSegue", sender: nil)
}
}
@chelseatroy
chelseatroy / ExampleViewController.swift
Created January 26, 2017 00:49
Load from Storyboard iOS Example
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 January 27, 2017 23:26
Load from Storyboard Example iOS
import XCTest
import Hamcrest
import FutureKit
@testable import MyExampleApp
class ExampleViewControllerTest: XCTestCase {
...