Skip to content

Commit 1c30c1d

Browse files
authored
Merge pull request #885 from Quick/tonever-for-objc
[ObjC] Add `toNever` expectation
2 parents fa6c58f + e305c44 commit 1c30c1d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Sources/Nimble/Adapters/NMBExpectation.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ public class NMBExpectation: NSObject {
116116
return toEventuallyNotWithDescription
117117
}
118118

119+
@objc public var toNever: (NMBPredicate) -> Void {
120+
return { predicate in
121+
self.expectValue.toNever(
122+
from(objcPredicate: predicate),
123+
until: self._timeout,
124+
description: nil
125+
)
126+
}
127+
}
128+
129+
@objc public var toNeverWithDescription: (NMBPredicate, String) -> Void {
130+
return { predicate, description in
131+
self.expectValue.toNever(
132+
from(objcPredicate: predicate),
133+
until: self._timeout,
134+
description: description
135+
)
136+
}
137+
}
138+
139+
@objc public var neverTo: (NMBPredicate) -> Void {
140+
return toNever
141+
}
142+
143+
@objc public var neverToWithDescription: (NMBPredicate, String) -> Void {
144+
return toNeverWithDescription
145+
}
146+
119147
@objc public class func failWithMessage(_ message: String, file: FileString, line: UInt) {
120148
fail(message, location: SourceLocation(file: file, line: line))
121149
}

Tests/NimbleTests/objc/ObjCAsyncTest.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,39 @@ - (void)testAsyncCallback {
5757
});
5858
}
5959

60+
- (void)testToNeverPositiveMatches {
61+
__block id value = @0;
62+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
63+
value = @1;
64+
});
65+
expect(value).toNever(beGreaterThan(1));
66+
67+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
68+
value = @0;
69+
});
70+
expect(value).neverTo(beGreaterThan(1));
71+
}
72+
73+
- (void)testToNeverNegativeMatches {
74+
__block id value = @0;
75+
expectFailureMessage(@"expected to never equal <0>, got <0>", ^{
76+
expect(value).toNever(equal(0));
77+
});
78+
expectFailureMessage(@"expected to never equal <0>, got <0>", ^{
79+
expect(value).neverTo(equal(0));
80+
});
81+
expectFailureMessage(@"expected to never equal <1>, got <1>", ^{
82+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
83+
value = @1;
84+
});
85+
expect(value).toNever(equal(1));
86+
});
87+
expectFailureMessage(@"expected to never equal <1>, got <1>", ^{
88+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
89+
value = @1;
90+
});
91+
expect(value).neverTo(equal(1));
92+
});
93+
}
94+
6095
@end

0 commit comments

Comments
 (0)