-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
Warning[:deprecated] = true by default in RSpec #2867
Comments
For RSpec 3.x I won't change the default, I'd consider that a breaking change. If there was overwhelming support for it in 4.x I might consider making it the default as long as it was suppressible, but I'd prefer it remained an opt in behaviour (because there are very verbose libraries out there) which we already allow (with An alternative I'd happily consider, is to place it into our generated spec helper, with a comment explaining what it is. This has the effect of effectively being on by default (as most new projects end up using our default spec helper from what I've seen), but also explaining how to not have it for verbose projects without having to look it up. |
I think you are confusing with For instance, it doesn't make much sense to test a gem on 2.7 but not address or even see the keyword arguments deprecation warnings. In Ruby <= 2.6, deprecation warnings would typically be shown even with
Do you have examples that actually emit many deprecation warnings and support Ruby 2.7?
It would only apply to new projects though, which seems a big drawback. Finally I'd like to highlight this is not a personal request but part of the plan of ruby-core for deprecation warnings in Ruby 2.7+, as mentioned on the ruby-core issue. |
For more background on the change in 2.7.2, I think this comment is helpful: https://bugs.ruby-lang.org/issues/16345#note-31 |
I am not confused, it is not up to us to decide to emit deprecation warnings, if Ruby makes that choice, that is there decision, but they got push back and added this option to turn them on at a users discretion.
But that is not our decision to make for other libraries. We already check that RSpec itself produces no warnings, it's even part of our spec suite.
Rails projects where the majority of code lives upstream in gems of various ages.
It prevents us making a breaking change and allowing to introduce it earlier.
They made this opt in after push back by the community about the level of deprecation warnings, that same push back applies here, we are following the Ruby community here. |
I guessed that because you mentioned
That's a simplistic view of it. It was made opt-in because for end users (!= developers) the deprecation warnings cannot be acted on. If you still disagree, how about asking RSpec users or gem maintainers using RSpec about it? @mame @jeremyevans Could you share your opinion here? |
BTW, part of my motivation to fix this is I've seen many gems that try to be compatible with Ruby 3, often do it incorrectly, and they probably completely missed the deprecation warnings of 2.7, which could have been useful to migrate earlier or more easily. Due in part to test frameworks not showing these important warnings by default. |
My opinion is that Ruby should always emit deprecation warnings, and software designed for end users should use @eregon is right that ruby-core expected that test library developers would enable deprecation warnings by default. If RSpec doesn't want to do that, considering RSpec's popularity, we (ruby-core) should consider reverting the change in Ruby and enable deprecation warnings by default. |
It's not up to us to ease the migration of the code that is outside of our control. |
Deprecations are warnings. I mentioned RSpec's own
I saw developer push back about it on the Ruby issue tracker, as I am not privy to the internal debates of the Ruby team I took that to be the cause of the subsequent change, I apologise for not investigating further at the time, but I've yet to come across a user of Ruby who is not a developer.
It would have been an option for us to do that at the release of Ruby 2.7 had someone reached out and made that expectation, we could have flagged this mode for Ruby 2.7 only and turned it on. However it is now a breaking change, in that previous Ruby code bases that passed without warnings would suddenly gain warnings from a point release of RSpec. I'm happy to discuss turning this on in RSpec 4. |
Actually up to and included Ruby 2.7.1, deprecation were shown by default.
Yes, I think such issues should have been opened right after the decision was made to disable deprecation warnings by default in Ruby 2.7.2. Unfortunately it seem committers at the time forgot or did not think about it (I guess they might have been busy with the 2.7.2 release). I think RSpec 4 would be a fine target for this change if it's deemed too incompatible in RSpec 3. |
@JonRowe I can work on this for RSpec 4, ok to tag this ticket as such? |
We have a couple of options either it could just be a
|
FWIW, RSpec is the only popular test framework still not showing deprecation warnings to its users (https://bugs.ruby-lang.org/issues/17591). That means it makes it much harder for RSpec users to notice deprecated methods, and most likely they won't notice until something breaks hard, effectively destroying a significant part of ruby-core's efforts to have a nice transition path with deprecation, etc. Yes, it's unfortunate this wasn't asked immediately after 2.7.2 came out, but the current situation is problematic. |
Maybe we should think wider how to address this and be compatible enough. It has been two years.
Or maybe a message as gem/bundle install time suggesting to enable deprecation warnings and showing how. Any thoughts on that? |
I'll happily review a PR with a config option that sets this, and prints a warning if its not set for Rubies that support it; the message should specify how to remove the warning, and the config option should support just silencing the warning without turning it on. I will not support adding an install time message, I do not wish to party hard in this project. |
Subject of the issue
See https://bugs.ruby-lang.org/issues/17591.
The plan of ruby-core hiding deprecation warnings in Ruby 2.7.2 is that test frameworks, like rspec, should enable them by default (with
Warning[:deprecated] = true if Warning.respond_to?(:[]=)
, which only enables deprecation warnings).This is important so that developers see warnings in development, and that they see the warnings before updating to the next Ruby version.
Of course, RSpec users can still choose to disable deprecation warnings explicitly if they really want with
Warning[:deprecated] = false
(but then they should not be surprised when it breaks hard when updating to a newer Ruby, that's the cost of ignoring deprecation warnings).Somewhat related to #2809.
Your environment
Steps to reproduce
rspec some_spec.rb
Expected behavior
Actual behavior
No warnings in 2.7:
Breaks hard in 3.0:
The text was updated successfully, but these errors were encountered: