Skip to content

Commit

Permalink
Merge pull request #20 from metova/feature/AlertControllerAssertion
Browse files Browse the repository at this point in the history
Feature/alert controller assertion
  • Loading branch information
lgauthier committed Jul 19, 2017
2 parents fcd3026 + d596f9b commit c48e787
Show file tree
Hide file tree
Showing 19 changed files with 632 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
- Added assertion for UIControl target/action.
- Added assertion for UISegmentedControl segment titles.
- Added async testing utility.
- Added assertion for displaying UIAlertControllers.

## 1.0.0

Expand Down
41 changes: 29 additions & 12 deletions MetovaTestKit.xcodeproj/project.pbxproj
Expand Up @@ -24,14 +24,18 @@
4A8AD4F11CDEB6C30085984D /* TestableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8AD4EF1CDEB6C30085984D /* TestableViewController.swift */; };
4A8AD4F21CDEB6C30085984D /* TestableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A8AD4F01CDEB6C30085984D /* TestableViewController.xib */; };
4A8AD4F41CDEB7A60085984D /* TestableProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8AD4F31CDEB7A60085984D /* TestableProtocolTests.swift */; };
6E2368361F046B26008E3231 /* QuotedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2368351F046B26008E3231 /* QuotedString.swift */; };
6E2616EC1F18060200D9B507 /* UIAlertControllerTestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2616EB1F18060200D9B507 /* UIAlertControllerTestingTests.swift */; };
6E8D4B081EB7C5DF001284FD /* FailureRecording.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B071EB7C5DF001284FD /* FailureRecording.swift */; };
6E8D4B0C1EB7CF68001284FD /* UIControlTestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B0B1EB7CF67001284FD /* UIControlTestingTests.swift */; };
6E8D4B191EB8138B001284FD /* UIControlAssertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B181EB8138B001284FD /* UIControlAssertions.swift */; };
6E8D4B1E1EB8D660001284FD /* FailureRecordingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B1D1EB8D660001284FD /* FailureRecordingTests.swift */; };
6E8D4B221EB941B9001284FD /* UISegmentedControlAssertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B211EB941B9001284FD /* UISegmentedControlAssertions.swift */; };
6E8D4B241EB941F8001284FD /* Array+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8D4B231EB941F8001284FD /* Array+Utilities.swift */; };
6E98F0BB1F15931D009C15FB /* QuotedStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E98F0BA1F15931D009C15FB /* QuotedStringTests.swift */; };
6EC1A6B01EBCDDAF000DEFA6 /* XCTestCase+AsyncTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EC1A6AF1EBCDDAF000DEFA6 /* XCTestCase+AsyncTesting.swift */; };
6EC1A6B31EBCE2E2000DEFA6 /* AsyncTestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EC1A6B21EBCE2E2000DEFA6 /* AsyncTestingTests.swift */; };
6ED689011EFC2D3C0040C243 /* UIAlertControllerAssertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED689001EFC2D3C0040C243 /* UIAlertControllerAssertions.swift */; };
6EF9B23B1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EF9B23A1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -67,26 +71,30 @@
4A771F2F1D4C144400EFD0B8 /* MTKBrokenConstraintCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MTKBrokenConstraintCounter.m; path = ConstraintTesting/MTKBrokenConstraintCounter.m; sourceTree = "<group>"; };
4A771F321D4C155700EFD0B8 /* MTKConstraintTester.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKConstraintTester.swift; path = ConstraintTesting/MTKConstraintTester.swift; sourceTree = "<group>"; };
4A771F341D4C173300EFD0B8 /* ConstraintTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintTestingTests.swift; sourceTree = "<group>"; };
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTKBaseTestCase.swift; sourceTree = "<group>"; };
4A8AD4E81CDEA2A30085984D /* MTKTestable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKTestable.swift; path = ViewControllerTesting/MTKTestable.swift; sourceTree = "<group>"; };
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKBaseTestCase.swift; path = "Supporting Test Files/MTKBaseTestCase.swift"; sourceTree = "<group>"; };
4A8AD4E81CDEA2A30085984D /* MTKTestable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKTestable.swift; path = Testable/MTKTestable.swift; sourceTree = "<group>"; };
4A8AD4EA1CDEA2B60085984D /* MTKExceptionTesting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKExceptionTesting.swift; path = ExceptionTesting/MTKExceptionTesting.swift; sourceTree = "<group>"; };
4A8AD4EC1CDEA53A0085984D /* MTKTestable+UIViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "MTKTestable+UIViewController.swift"; path = "ViewControllerTesting/MTKTestable+UIViewController.swift"; sourceTree = "<group>"; };
4A8AD4EF1CDEB6C30085984D /* TestableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestableViewController.swift; path = SupportingTestFiles/TestableViewController.swift; sourceTree = "<group>"; };
4A8AD4F01CDEB6C30085984D /* TestableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TestableViewController.xib; path = SupportingTestFiles/TestableViewController.xib; sourceTree = "<group>"; };
4A8AD4EC1CDEA53A0085984D /* MTKTestable+UIViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "MTKTestable+UIViewController.swift"; path = "Testable/MTKTestable+UIViewController.swift"; sourceTree = "<group>"; };
4A8AD4EF1CDEB6C30085984D /* TestableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestableViewController.swift; path = "Test Data/TestableViewController.swift"; sourceTree = "<group>"; };
4A8AD4F01CDEB6C30085984D /* TestableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TestableViewController.xib; path = "Test Data/TestableViewController.xib"; sourceTree = "<group>"; };
4A8AD4F31CDEB7A60085984D /* TestableProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestableProtocolTests.swift; sourceTree = "<group>"; };
4A8AD4F51CDEDF110085984D /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
4A8AD4F71CDEE4220085984D /* .travis.yml */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
4AB9A3E01CDF6AB00021B6B8 /* Gemfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; indentWidth = 2; path = Gemfile; sourceTree = "<group>"; };
6E8D4B071EB7C5DF001284FD /* FailureRecording.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FailureRecording.swift; path = Internal/FailureRecording.swift; sourceTree = "<group>"; };
6E8D4B0B1EB7CF67001284FD /* UIControlTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControlTestingTests.swift; sourceTree = "<group>"; };
6E2368351F046B26008E3231 /* QuotedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = QuotedString.swift; path = "Internal Utilities/QuotedString.swift"; sourceTree = "<group>"; };
6E2616EB1F18060200D9B507 /* UIAlertControllerTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIAlertControllerTestingTests.swift; path = "UIKit Testing Tests/UIAlertControllerTestingTests.swift"; sourceTree = "<group>"; };
6E8D4B071EB7C5DF001284FD /* FailureRecording.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FailureRecording.swift; path = "Internal Utilities/FailureRecording.swift"; sourceTree = "<group>"; };
6E8D4B0B1EB7CF67001284FD /* UIControlTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIControlTestingTests.swift; path = "UIKit Testing Tests/UIControlTestingTests.swift"; sourceTree = "<group>"; };
6E8D4B181EB8138B001284FD /* UIControlAssertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIControlAssertions.swift; path = UIKitTesting/UIControlAssertions.swift; sourceTree = "<group>"; };
6E8D4B1A1EB8154A001284FD /* .ruby-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".ruby-version"; sourceTree = "<group>"; };
6E8D4B1D1EB8D660001284FD /* FailureRecordingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FailureRecordingTests.swift; sourceTree = "<group>"; };
6E8D4B1D1EB8D660001284FD /* FailureRecordingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FailureRecordingTests.swift; path = "Internal Utilities Tests/FailureRecordingTests.swift"; sourceTree = "<group>"; };
6E8D4B211EB941B9001284FD /* UISegmentedControlAssertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UISegmentedControlAssertions.swift; path = UIKitTesting/UISegmentedControlAssertions.swift; sourceTree = "<group>"; };
6E8D4B231EB941F8001284FD /* Array+Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Array+Utilities.swift"; path = "Internal/Array+Utilities.swift"; sourceTree = "<group>"; };
6E8D4B231EB941F8001284FD /* Array+Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Array+Utilities.swift"; path = "Internal Utilities/Array+Utilities.swift"; sourceTree = "<group>"; };
6E98F0BA1F15931D009C15FB /* QuotedStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = QuotedStringTests.swift; path = "Internal Utilities Tests/QuotedStringTests.swift"; sourceTree = "<group>"; };
6EC1A6AF1EBCDDAF000DEFA6 /* XCTestCase+AsyncTesting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTestCase+AsyncTesting.swift"; sourceTree = "<group>"; };
6EC1A6B21EBCE2E2000DEFA6 /* AsyncTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsyncTestingTests.swift; sourceTree = "<group>"; };
6EF9B23A1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UISegmentedControlTestingTests.swift; sourceTree = "<group>"; };
6EC1A6B21EBCE2E2000DEFA6 /* AsyncTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AsyncTestingTests.swift; path = "Asynchronous Testing Tests/AsyncTestingTests.swift"; sourceTree = "<group>"; };
6ED689001EFC2D3C0040C243 /* UIAlertControllerAssertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIAlertControllerAssertions.swift; path = UIKitTesting/UIAlertControllerAssertions.swift; sourceTree = "<group>"; };
6EF9B23A1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UISegmentedControlTestingTests.swift; path = "UIKit Testing Tests/UISegmentedControlTestingTests.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -229,6 +237,7 @@
children = (
6E8D4B181EB8138B001284FD /* UIControlAssertions.swift */,
6E8D4B211EB941B9001284FD /* UISegmentedControlAssertions.swift */,
6ED689001EFC2D3C0040C243 /* UIAlertControllerAssertions.swift */,
);
name = UIKitTesting;
sourceTree = "<group>";
Expand All @@ -238,6 +247,7 @@
children = (
6E8D4B071EB7C5DF001284FD /* FailureRecording.swift */,
6E8D4B231EB941F8001284FD /* Array+Utilities.swift */,
6E2368351F046B26008E3231 /* QuotedString.swift */,
);
name = "Internal Utilities";
sourceTree = "<group>";
Expand All @@ -247,6 +257,7 @@
children = (
6E8D4B0B1EB7CF67001284FD /* UIControlTestingTests.swift */,
6EF9B23A1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift */,
6E2616EB1F18060200D9B507 /* UIAlertControllerTestingTests.swift */,
);
name = "UIKit Testing Tests";
sourceTree = "<group>";
Expand All @@ -264,6 +275,7 @@
isa = PBXGroup;
children = (
6E8D4B1D1EB8D660001284FD /* FailureRecordingTests.swift */,
6E98F0BA1F15931D009C15FB /* QuotedStringTests.swift */,
);
name = "Internal Utilities Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -345,7 +357,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = "";
LastSwiftUpdateCheck = 0730;
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Metova;
TargetAttributes = {
Expand All @@ -365,6 +377,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 4A3CFEED1CDD5F37003EF6F0;
productRefGroup = 4A3CFEF81CDD5F37003EF6F0 /* Products */;
Expand Down Expand Up @@ -432,8 +445,10 @@
buildActionMask = 2147483647;
files = (
6E8D4B241EB941F8001284FD /* Array+Utilities.swift in Sources */,
6E2368361F046B26008E3231 /* QuotedString.swift in Sources */,
4A771F331D4C155700EFD0B8 /* MTKConstraintTester.swift in Sources */,
4A771F311D4C144400EFD0B8 /* MTKBrokenConstraintCounter.m in Sources */,
6ED689011EFC2D3C0040C243 /* UIAlertControllerAssertions.swift in Sources */,
4A8AD4EB1CDEA2B60085984D /* MTKExceptionTesting.swift in Sources */,
4A8AD4ED1CDEA53A0085984D /* MTKTestable+UIViewController.swift in Sources */,
6E8D4B191EB8138B001284FD /* UIControlAssertions.swift in Sources */,
Expand All @@ -451,9 +466,11 @@
files = (
4A8AD4F11CDEB6C30085984D /* TestableViewController.swift in Sources */,
4A771F351D4C173300EFD0B8 /* ConstraintTestingTests.swift in Sources */,
6E98F0BB1F15931D009C15FB /* QuotedStringTests.swift in Sources */,
4A771FC91D4D534200EFD0B8 /* MTKBaseTestCase.swift in Sources */,
6EF9B23B1EBBA65600B87FA3 /* UISegmentedControlTestingTests.swift in Sources */,
4A8AD4F41CDEB7A60085984D /* TestableProtocolTests.swift in Sources */,
6E2616EC1F18060200D9B507 /* UIAlertControllerTestingTests.swift in Sources */,
6EC1A6B31EBCE2E2000DEFA6 /* AsyncTestingTests.swift in Sources */,
4A3CFFCE1CDE1548003EF6F0 /* ExceptionTestingTests.swift in Sources */,
6E8D4B0C1EB7CF68001284FD /* UIControlTestingTests.swift in Sources */,
Expand Down
Expand Up @@ -31,18 +31,11 @@ import Foundation

extension Sequence where Iterator.Element == String {

/// Convenience method for generating a comma separated list of items in qutoes. The last item will be preceded with "and" as well as an Oxford comma.
/// Convenience method for generating a comma separated list of items.
///
/// - Returns: A comma separated list of items where each item is surrounded by quotes.
func commaSeparatedQuotedList() -> String {
/// - Returns: A comma separated list of items.
func commaSeparatedList() -> String {

var itemsInQuotes = map { "\"\($0)\"" }

if itemsInQuotes.count > 1 {
let lastItem = itemsInQuotes.removeLast()
return itemsInQuotes.joined(separator: ", ") + ", and \(lastItem)"
}

return itemsInQuotes.joined(separator: ", ")
return "[" + map({ "\($0)" }).joined(separator: ", ") + "]"
}
}
43 changes: 43 additions & 0 deletions MetovaTestKit/Internal Utilities/QuotedString.swift
@@ -0,0 +1,43 @@
//
// QuotedString.swift
// MetovaTestKit
//
// Created by Logan Gauthier on 6/28/17.
// Copyright © 2017 Metova. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation

/// Utility for producing descriptions for `String?` types without being wrapped in "Optional()".
///
/// - Parameter string: An optional String.
/// - Returns: The unwrapped value in quotes, if it exists. Otherwise, "nil".
func quotedString(_ string: String?) -> String {

guard let string = string else {
return "nil"
}

return "\"\(string)\""
}
File renamed without changes.

0 comments on commit c48e787

Please sign in to comment.