-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Reduce NMBObjCMatcher usages #600
Conversation
803e746
to
dbc91fa
Compare
@objc public class func beFalseMatcher() -> NMBMatcher { | ||
return NMBPredicate { actualExpression in | ||
let expr = actualExpression.cast { value -> Bool? in | ||
guard let value = value else { return nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil
should not be converted to false
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch. Should we add a test that covers this difference between beFalse()
and beFalsy()
? We're also accepting values that fail to cast to NSNumber
, should we also return nil if the cast fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is already covered here:
Nimble/Tests/NimbleTests/objc/ObjCBeFalseTest.m
Lines 24 to 29 in 7de0814
expectNilFailureMessage(@"expected to be false, got <nil>", ^{ expect(nil).to(beFalse()); }); expectNilFailureMessage(@"expected to not be false, got <nil>", ^{ expect(nil).toNot(beFalse()); }); expect(nil).to(beFalsy()); Nimble/Tests/NimbleTests/objc/ObjCBeFalsyTest.m
Lines 26 to 28 in 7de0814
expectFailureMessage(@"expected to not be falsy, got <nil>", ^{ expect(nil).toNot(beFalsy()); });
Previously the behavior is ensured by NMBObjCMatcher(canMatchNil: false)
:
Nimble/Sources/Nimble/Adapters/NMBObjCMatcher.swift
Lines 47 to 52 in 7de0814
if !canMatchNil { | |
if try actualExpression.evaluate() == nil { | |
failureMessage.postfixActual = " (use beNil() to match nils)" | |
return false | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I wanted to say is that the message
nil
should not be converted tofalse
here.
is only applicable to the new NMBPredicate
impl in this PR, but not to the previous NMBObjCMatcher
impl.
@@ -13,7 +13,6 @@ - (void)testPositiveMatches { | |||
expect(@"hello world!").toNot(endWith(@"hello")); | |||
expect(array).to(endWith(@2)); | |||
expect(array).toNot(endWith(@1)); | |||
expect(@1).toNot(contain(@"foo")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing contain
matcher in ObjCEndWithTest.m
is odd (and the fact the test is passing is odd as well) 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment, but lgtm 👍
@objc public class func beFalseMatcher() -> NMBMatcher { | ||
return NMBPredicate { actualExpression in | ||
let expr = actualExpression.cast { value -> Bool? in | ||
guard let value = value else { return nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch. Should we add a test that covers this difference between beFalse()
and beFalsy()
? We're also accepting values that fail to cast to NSNumber
, should we also return nil if the cast fails?
dbc91fa
to
3ff206a
Compare
I will go ahead 🚀 Thanks for the review @sharplet! |
Reduce NMBObjCMatcher usages
See also #592.