-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The `isIdenticalTo()` performs a `===` on subjects that are `AnyObject`. - The `isNotIdenticalTo()` performs a `!==` on subjects that are `AnyObject`. Closes #109.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public extension Subject where T: AnyObject { | ||
/// Asserts that the actual value is identical (===) to expected. | ||
@discardableResult func isIdenticalTo( | ||
_ expected: T, | ||
file: StaticString = #file, line: UInt = #line | ||
) -> Self { | ||
return doAssert( | ||
failWith: Failure( | ||
file: file, | ||
line: line, | ||
Fact("expected", expected), | ||
Fact("to be identical to", actual) | ||
) | ||
) { | ||
actual === expected | ||
} | ||
} | ||
|
||
/// Asserts that the actual value is not identical (!==) to expected. | ||
@discardableResult func isNotIdenticalTo( | ||
_ expected: T, | ||
file: StaticString = #file, line: UInt = #line | ||
) -> Self { | ||
return doAssert( | ||
failWith: Failure( | ||
file: file, | ||
line: line, | ||
Fact("expected not to be identical to", expected) | ||
) | ||
) { | ||
actual !== expected | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@testable import Truth | ||
import XCTest | ||
|
||
class AnyObectAssertionsTests: XCTestCase { | ||
class Foo { | ||
var name: String | ||
|
||
init(name: String) { | ||
self.name = name | ||
} | ||
} | ||
|
||
func test_isIdenticalTo_WithIdenticalObjs_Succeeds() throws { | ||
let actual = Foo(name: "Jim") | ||
let expected = actual | ||
assertNoFailures { $0.that(actual).isIdenticalTo(expected) } | ||
} | ||
|
||
func test_isIdenticalTo_WithDifferentObjs_Fails() throws { | ||
let actual = Foo(name: "Jim") | ||
let expected = Foo(name: "Jim") | ||
assertFailure([Fact("expected", expected), Fact("to be identical to", actual)]) { | ||
$0.that(actual).isIdenticalTo(expected) | ||
} | ||
} | ||
|
||
func test_isNotIdenticalTo_WithDifferentObjs_Succeeds() throws { | ||
let actual = Foo(name: "Jim") | ||
let expected = Foo(name: "Jim") | ||
assertNoFailures { $0.that(actual).isNotIdenticalTo(expected) } | ||
} | ||
|
||
func test_isNotIdenticalTo_WithIdenticalObjs_Fails() throws { | ||
let actual = Foo(name: "Jim") | ||
let expected = actual | ||
assertFailure([Fact("expected not to be identical to", expected)]) { | ||
$0.that(actual).isNotIdenticalTo(expected) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters