Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability for MTKTestable test(_:) blocks to throw #37

Merged
merged 6 commits into from Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions MetovaTestKit/Testable/MTKTestable+UIViewController.swift
Expand Up @@ -36,10 +36,10 @@ public extension MTKTestable where Self: UIViewController {

- parameter testBlock: The block of tests to run.
*/
static func test(_ testBlock: (Self) -> Void) {
static func test(_ testBlock: (Self) throws -> Void) rethrows {
let testVC = instanceForTesting()
testVC.loadView()
testVC.viewDidLoad()
testBlock(testVC)
try testBlock(testVC)
}
}
2 changes: 1 addition & 1 deletion MetovaTestKit/Testable/MTKTestable.swift
Expand Up @@ -74,7 +74,7 @@ public protocol MTKTestable {

- parameter testBlock: A block of code containing tests to run.
*/
static func test(_ testBlock: (TestableItem) -> Void)
static func test(_ testBlock: (TestableItem) throws -> Void) rethrows

/**
Asks the `MTKTestable` type for a new instance in order to be used for testing. This method should provide a new instance every time.
Expand Down
10 changes: 10 additions & 0 deletions MetovaTestKitTests/Test Data/TestableViewController.swift
Expand Up @@ -55,6 +55,16 @@ class TestableViewController: UIViewController {
testLabel.text = TestableViewController.TestLabelString
testButton.setTitle(TestableViewController.TestButtonString, for: .normal)
}

func throwError() throws {

throw ViewControllerError()
}
}

extension TestableViewController {

struct ViewControllerError: Error { }
}

// Implementing this method and marking conformance to MTKTestable protocol means we inherit the default implementation of the test(_:) method defined in the extension for the protocol for UIViewControllers.
Expand Down
Expand Up @@ -59,4 +59,15 @@ class TestableProtocolTests: MTKBaseTestCase {

waitForExpectations(timeout: 0, handler: nil)
}

func testErrorIsThrown() {
nhgrif marked this conversation as resolved.
Show resolved Hide resolved

XCTAssertThrowsError(

try TestableViewController.test { testVC in

try testVC.throwError()
}
)
}
}