Comments (2)
After thinking on this for a bit, here's my conclusion: toNever
in Nimble 13.2.1 is exhibiting the correct behavior. The equal
matcher return MatcherStatus.fail
when it encounters nil, and toNever
should fail/immediately exit when the matcher stops returning MatcherStatus.doesNotMatch
.
This issue is actually that you expect equal
to return MatcherStatus.doesNotMatch
when the given expression is nil. Which is reasonable. After all, nil
is not equal to "bar"
, so why is Nimble marking that as a test failure?
Usually, nil
is treated as a special case in most matchers, where the matcher will fail regardless of whether it's a "to" or "toNot" style. For example, expect(nil as Int?).toNot(equal(0))
and expect(nil as Int?).to(equal(0))
will both be marked as failing. This is a baggage from the common Objective-C idiom of returning nil & setting an error pointer on error that was still present in Swift prior to the swift error system (e.g. expect([subject doTheThingWithError:&error]).to(equal(someValue))
should fail when nil is returned, because Objective-C doesn't have the concept of non-optional objects).
Considering that Objective-C is not used nearly as much as Swift is, we should probably special-case on Objective-C for the equal
matcher. That is expect(nil).to(equal(someValue))
in Objective-C should return MatcherStatus.fail, but in Swift, it should return MatcherStatus.doesNotMatch (unless someValue
is actually nil, in which case it should be the same as beNil()
.). We should also do the same for a bunch of other matchers in Nimble as well.
Relatedly, I've been meaning to do a bunch of work so that Matchers have to explicitly declare that they take in Optionals to operate on them (and similarly, that expect
and require
should not even compile if you pass in an expression returning Optionals to a Matcher that doesn't take Optionals).
All of this work is a breaking change, and something that will require a new major version.
I'm going to close this, and add another issue to specifically re-examine how we treat nils in Nimble.
Until then, as a very silly workaround, you could do an inline expression in expect
to return a non-nil value:
expect { value ?? "bar" }.toNever(equal("foo")).
from nimble.
@younata thanks for your efforts maintaining this project.
Noticed this behaviour in 13.2.1. 13.2.0 a test case with above scenario passes.
Perhaps the changes in https://github.com/Quick/Nimble/pull/1121/files brought it up.
I am unfamiliar with Nimble's codebase to verify if the issue surfaced is an expected behaviour that was fixed in 13.2.1. If so please let me know, I will close this issue.
from nimble.
Related Issues (20)
- toEventually in Xcode 15 somtimes results in "main run loop was unresponsive" HOT 1
- Question: Advice on using toEventually with UIViewController/UIView in XCTestCase
- Discussion about the project setup and Carthage usage HOT 2
- Quick 7.3.0 and Nimble 13.0.0 ERROR : "Instance member 'testVariablesNotNil' cannot be used on type 'ConditionSelectionTests'" HOT 1
- Attempted to report a test failure to XCTest while no test case was running HOT 6
- Add a `require` function, similar to `expect`, which either returns the expression if it passes, or throws if it fails.
- Privacy Manifest
- Move matcher documentation out of README.md
- Support localization in matchers.
- `throwAssertion` does not work on macOS HOT 2
- Release 13.2.0 is not available through cocoapods source repo/CDN HOT 6
- Trying to write my own matcher but predicate is not working as I expected HOT 1
- Memoize errors
- `expect(nil).toAlways(equal(0))` incorrectly succeeds HOT 5
- Reexamine how Nimble treats nils in Swift code.
- `require(nil).to(beNil())` will incorrectly fail & throw an error.
- Calling waitUntil in a QuickConfiguration times out for AsyncSpec HOT 1
- Using Nimble types with @MainActor gives a warning when SWIFT_STRICT_CONCURRENCY=targeted due to lack of Sendable conformance HOT 4
- When the current main branch will be in a release? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimble.