Closed 0llirocks closed 3 months ago
The config options RSpec provides changes the behaviour to raise if RSpec warns you about some deprecations, not just any part. So there’s no out of the box solution.
However, RSpec’s own spec suite is strict about warnings issued in other parts of the app, catches them all and fails examples if there were warnings. You are welcome to explore our spec suite to see how this is done.
Apologies, I agree that the docs are a bit confusing here, the --warning
and config.warning =
settings turn on a flag within Ruby called $VERBOSE
which is a bit of a legacy handover as Ruby now tends to warn about things directly.
Our raise_on_warning
flag conversley is intended for our own warnings. I've tweaked the documentation here to better reflect that.
If we could raise on Ruby warnings easily I would totally support that, but the problem is they are essentially output to std err without anyway (that I know of) to be notified of them. What @pirj is referring to above is what we do within our own test suite, we replace stderr with essentially a mock which allows us to error our own suite on any output to std err.
That is something we could expose publically as an opt in, but it would probably have to be quite explicit that its on any output to std err and not specifically Ruby warnings.
@JonRowe Thank you for the explanation and the improved documentation 👍
Test with warning should fail
I am currently trying to let my test fail, if a warning from ruby is thrown. I assumed using _raise_errors_fordeprecations! would be the correct config, but I am not sure whether a warning is considered as deprecation. I also tried _raise_onwarning but as the comment from SO pointed out, this only applies to rspec warnings (if this is true, the documentation isn't 100% clear to me). Maybe this isn't an issue, but just a misunderstanding from my point of view. What would be the correct config to let my test fail?
Your environment
Steps to reproduce
.rspec
spec_helper.rb
test_spec.rb
Expected behavior
Test would fail.
Actual behavior