Skip to content

Conversation

byroot
Copy link
Contributor

@byroot byroot commented Dec 17, 2024

Fix: #37

Since Ruby 2.7.2, Ruby expect test frameworks to enable deprecation warnings so users get advance notice of future breaking changes.

I implemented it as specified in #37 (comment)

3.99 deprecation for boolean config.warnings = true/config.warnings = false #268

@byroot
Copy link
Contributor Author

byroot commented Dec 17, 2024

Hum, CI fails because of the 100% coverage target, but I don't know how I can satisfy this given some code path are only ever entered by some specific Ruby versions.

I'll try to do some static define instead but I don't think it will work.

@byroot byroot force-pushed the ruby-deprecation-warnings branch 2 times, most recently from f6cd89e to c5b0fd8 Compare December 17, 2024 10:03
@byroot
Copy link
Contributor Author

byroot commented Dec 17, 2024

Alright, I tried a few workarounds but they're all awful and don't pass the coverage check anyway, so I'll wait for instruction from the maintainers.

@byroot byroot force-pushed the ruby-deprecation-warnings branch 4 times, most recently from 1a11009 to 5d61ea4 Compare December 17, 2024 10:58
@byroot
Copy link
Contributor Author

byroot commented Dec 17, 2024

Alright, I believe the remaining errors are unrelated to my changes?

# Set Ruby deprecation warnings on or off.
def deprecation_warnings=(value)
@deprecation_warnings_set = true
::Warning[:deprecated] = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd rather we overload warnings= here to be one of: false :deprecations_only :all or true where true has the same effect as :all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that make sense, one downside I can think of however if that since regular warnings are quite verbose, it's likely that a bunch of projects have warnings = false and won't ever know about deprecation warnings.

So while I agree making it a difference config is a bit less clean, it give every RSpec user the opportunity to know about it.

But that's your call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that risk is low as false was the default, but I propose that the setting be :none, :deprecations_only and :all with true/false synonyms for :all/:none that in turn issue an RSpec deprecation warning asking people to update to the specifics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Ok, I'll try to implement that then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I think I implemented what you suggested. I'm not really familiar with RSpec codebase though, so hopefully it's implemented the proper way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last change, can we wrap this up into the above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't think I understand what you mean by that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonRowe I've tried inlining the deprecation_warnings= into warnings=, it ended up like this:

- self.deprecation_warnings = true
+ ::Warning[:deprecated] = true if defined?(::Warning) && ::Warning.respond_to?(:[]=)

Do you want to keep it as it is now, or inline?

The decision point here would be the ability to notice and remove those redundant checks when we drop Ruby below 2.7, correct?

I can add a commit here real quick.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous comment doesn't stand with us retiring Ruby 2.x support.
There are no downsides left from collapsing those two methods into one.

@byroot byroot force-pushed the ruby-deprecation-warnings branch from 5d61ea4 to d13009c Compare December 17, 2024 12:41
@benoittgt
Copy link
Member

benoittgt commented Dec 23, 2024

Hello Jean

I see two failures in feature specs.

bundle exec cucumber features/configuration/enable_global_dsl.feature:40
bundle exec cucumber features/command_line/ruby.feature:10

It happens in the CI after the simplecove coverage tests...

The issue seems related to how we try to report caller lines when using .warning. Maybe @JonRowe knows if .warning should be used here. I'm tempted to change how we report caller line. In my test I have 14 frames and with the current setup we are getting outside of frames before looping 3 times. 😄

Quick and dirty.

--- a/rspec-support/lib/rspec/support/caller_filter.rb
+++ b/rspec-support/lib/rspec/support/caller_filter.rb
@@ -65,7 +65,7 @@ module RSpec
 
         loop do
           stack = caller_locations(skip_frames, increment)
-          raise "No non-lib lines in stack" unless stack
+          break unless stack

Snippet to reproduce.

require "bundler/inline"
gemfile(true) do
  source "https://rubygems.org"
  gem 'rspec', path: '../rspec'
end

require 'rspec/autorun'

RSpec.describe 'Joyeux Noël' do
  it do
    expect({ :a => 1, :b => 2 }).not_to include(:a, :b)
  end
end

@byroot byroot force-pushed the ruby-deprecation-warnings branch from e835fa6 to 1e1fd1d Compare December 27, 2024 12:27
@byroot
Copy link
Contributor Author

byroot commented Dec 27, 2024

I fixed the typos in the message.

For the remaining failures, I don't know what to do, so I'll await further instructions.

@byroot byroot force-pushed the ruby-deprecation-warnings branch from 1e1fd1d to f654aaa Compare December 27, 2024 14:47
@byroot byroot force-pushed the ruby-deprecation-warnings branch from c836b7c to 5aec383 Compare December 27, 2024 14:50
@byroot byroot force-pushed the ruby-deprecation-warnings branch from 5aec383 to fc98e40 Compare December 28, 2024 20:00
@byroot
Copy link
Contributor Author

byroot commented Dec 28, 2024

The remaining failures are what @benoittgt pointed out.

Both failing scenarios are related to rspec/autorun:

Failing Scenarios:
cucumber features/command_line/ruby.feature:10 # Scenario: Require `rspec/autorun` from a spec file
cucumber features/configuration/enable_global_dsl.feature:40 # Scenario: By default rspec/autorun allows the DSL to be used globally

It fails because it's emitting a warning about config.warnings not being set.

@byroot
Copy link
Contributor Author

byroot commented Dec 28, 2024

Thanks for the fix, I was a bit stuck because of my limited knowledge of rspec.

One of the spec I added now complains but I can fix that.

@JonRowe
Copy link
Member

JonRowe commented Mar 18, 2025

Sorry for the silence on this, I'm going to merge this manually when I get the time to split it into 3.x and 4.x capable patches, but no input is needed beyond that.

@pirj

This comment was marked as outdated.

@pirj pirj requested a review from JonRowe September 14, 2025 10:58
@pirj pirj self-assigned this Oct 14, 2025
@pirj pirj changed the title Introduce config.deprecation_warnings Set :all/:deprecation_only/:none as options for config.warnings= Oct 14, 2025
@pirj
Copy link
Member

pirj commented Oct 14, 2025

I stumbled across our CLI --warnings option

Use the `--warnings` option to run specs with warnings enabled.

--warnings already works like :all.

@pirj pirj force-pushed the ruby-deprecation-warnings branch from d134557 to f6ea750 Compare October 14, 2025 18:16
@pirj
Copy link
Member

pirj commented Oct 14, 2025

The code to warn users to set the configuration option is getting complicated with the text config (.rspec) and CLI options sparser involved.
So far, I made it work with such a check:

      def warnings_set?
        @warnings_set || @preferred_options.key?(:warnings)

The second part is a shortcut, where a longer path would be to create some WarningsConfigurationManager, following the FilterManager and Order::ConfigurationManager, which feels overkill for what it does.

warnings_option.feature still fails. It expects no warnings if it doesn't pass --warning to rspec, but there's this warning to call config.warning= from spec_helper.rb. If we'd follow the path of adding this setup to this feature spec, whatever we set there undermines the elegance and the clarity of the spec.

What do you think of not warning when this option is not set, and default to :all?

I've pushed a temporary commit, but I'm not happy with the result, and would prefer taking another approach.

@JonRowe JonRowe force-pushed the ruby-deprecation-warnings branch from 56262ce to 917e56f Compare October 14, 2025 23:05
…ecations_only`.

Fix: rspec#37

Since Ruby 2.7.2, Ruby expect test frameworks to enable deprecation
warnings so users get advance notice of future breaking changes.
@JonRowe JonRowe force-pushed the ruby-deprecation-warnings branch from 917e56f to 52a37fe Compare October 14, 2025 23:09
@JonRowe JonRowe merged commit 9ff96be into rspec:main Oct 14, 2025
32 checks passed
@JonRowe
Copy link
Member

JonRowe commented Oct 14, 2025

I've finally gotten 4.0 and 3.99 into a place where this can be merged so I've tidied it up and done so 😂 Thanks for this @byroot I'm sorry its taken so long to land but the default warning behaviour in RSpec 4 will now be the equivalent of :deprecations_only with a recommendation to go to :all in the commented out project template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning[:deprecated] = true by default in RSpec

5 participants