-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Provide both strict (true/false) and loose (truthy/falsey) forms of the be/have matchers #1300
Comments
@fledman the problem with passing a Context for |
I'd prefer either adding a block that flips the config e.g you default to strict but run certain examples with:
or setting certain predicate matcher override modes
etc |
if a since I would prefer to impact a single assertion, rather than an example, a context, or the whole suite |
(although I am not in love with any of the three) semantics:
examples:
|
I love the ideas of @JonRowe or a new matcher. |
We kept # passes
expect(123.infinite?).to be_falsey
expect(-Float::INFINITY.infinite?).to be_truthy However, it's not obvious which predicates can return non-boolean values in Ruby. I don't have a definitive list for core/stdlib, and can only name We may issue a warning when a predicate matcher is used, and the return value is neither expect(123).to be_infinite
# Warning: `infitine?` predicate method called on `123` returned a non-boolean value. Consider using a less strict matcher instead `expect(123.infinite?).to be_truthy` |
Added a warning here: expect(-Float::INFINITY).to be_infinite
for easier migration to strict mode ones. config.set_strict_predicate_matcher_mode :be_infinite, :truthy I love the idea. |
Maybe we can have both strict (true/false) and loose (truthy/falsey) forms of the be/have matchers?
That way, regardless of which is the "default", it is easy to do inline adjustment
some syntax possibilities:
be_infinite
vsbe_infinite?
orhave_foo
vshave_foo!
be_ready(strict: false)
alternatively there could be an explicitly truthy/falsey matcher
expect(number).to reply(:infinite?)
expect(number).to respond_truthy(:infinite?)
Originally posted by @fledman in rspec/rspec-mocks#1218 (comment)
The text was updated successfully, but these errors were encountered: