Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 820227c

Browse files
authored
Merge pull request #2849 from rspec/remove-more-deprecations
Raise instead of warn on long-deprecated usages
2 parents 19be4b2 + 3201563 commit 820227c

File tree

6 files changed

+40
-66
lines changed

6 files changed

+40
-66
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Breaking Changes:
99
* Change the default `shared_context_metadata_behavior` to `apply_to_host_groups`
1010
and remove the configuration option. (Phil Pirozhkov, #2834)
1111
* Remove `run_all_when_everything_filtered` configuration option. (Phil Pirozhkov, #2845)
12+
* Raise on unsupported hook scope usage. (Phil Pirozhkov, #2849)
13+
* Raise on usage of metadata on suite-level scopes. (Phil Pirozhkov, #2849)
14+
* Raise an error when `fail_fast` is configured with
15+
an unsupported value. (Phil Pirozhkov, #2849)
1216

1317
Enhancements:
1418

lib/rspec/core/configuration.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ def fail_fast=(value)
203203
@fail_fast = value.to_i
204204

205205
if value.to_i == 0
206-
# TODO: in RSpec 4, consider raising an error here.
207-
RSpec.warning "Cannot set `RSpec.configuration.fail_fast`" \
206+
raise ArgumentError, "Cannot set `RSpec.configuration.fail_fast`" \
208207
" to `#{value.inspect}`. Only `true`, `false`, `nil` and integers" \
209208
" are valid values."
210-
@fail_fast = true
211209
end
212210
end
213211
end
@@ -1990,9 +1988,7 @@ def handle_suite_hook(scope, meta)
19901988
return nil unless scope == :suite
19911989

19921990
unless meta.empty?
1993-
# TODO: in RSpec 4, consider raising an error here.
1994-
# We warn only for backwards compatibility.
1995-
RSpec.warn_with "WARNING: `:suite` hooks do not support metadata since " \
1991+
raise ArgumentError, "WARNING: `:suite` hooks do not support metadata since " \
19961992
"they apply to the suite as a whole rather than " \
19971993
"any individual example or example group that has metadata. " \
19981994
"The metadata you have provided (#{meta.inspect}) will be ignored."

lib/rspec/core/hooks.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,13 @@ def register(prepend_or_append, position, *args, &block)
442442
scope, options = scope_and_options_from(*args)
443443

444444
if scope == :suite
445-
# TODO: consider making this an error in RSpec 4. For SemVer reasons,
446-
# we are only warning in RSpec 3.
447-
RSpec.warn_with "WARNING: `#{position}(:suite)` hooks are only supported on " \
448-
"the RSpec configuration object. This " \
449-
"`#{position}(:suite)` hook, registered on an example " \
450-
"group, will be ignored."
451-
return
445+
raise ArgumentError, "`#{position}(:suite)` hooks are only " \
446+
"supported on the RSpec configuration object. This " \
447+
"`#{position}(:suite)` hook, registered on an example " \
448+
"group, will be ignored."
452449
elsif scope == :context && position == :around
453-
# TODO: consider making this an error in RSpec 4. For SemVer reasons,
454-
# we are only warning in RSpec 3.
455-
RSpec.warn_with "WARNING: `around(:context)` hooks are not supported and " \
456-
"behave like `around(:example)."
450+
raise ArgumentError, "`around(:context)` hooks are not supported " \
451+
"and behave like `around(:example)`."
457452
end
458453

459454
hook = HOOK_TYPES[position][scope].new(block, options)

spec/rspec/core/configuration_spec.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,10 @@ module RSpec::Core
110110
allow(RSpec).to receive(:warning)
111111
end
112112

113-
it 'prints warning' do
114-
config.fail_fast = 'yes'
115-
expect(RSpec).to have_received(:warning).with(/Cannot set `RSpec.configuration.fail_fast`/i)
116-
end
117-
118-
it 'is set to true' do
119-
config.fail_fast = 'yes'
120-
expect(config.fail_fast).to eq true
113+
it 'raises an error' do
114+
expect {
115+
config.fail_fast = 'yes'
116+
}.to raise_error(ArgumentError, /Cannot set `RSpec.configuration.fail_fast`/i)
121117
end
122118
end
123119
end

spec/rspec/core/hooks_spec.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -484,32 +484,30 @@ def yielder
484484
])
485485
end
486486

487-
it 'emits a warning for `around(:context)`' do
488-
expect(RSpec).to receive(:warn_with).with(a_string_including(
489-
'`around(:context)` hooks are not supported'
490-
))
491-
RSpec.describe do
492-
around(:context) { }
493-
end
487+
it 'raises an error for `around(:context)`' do
488+
expect {
489+
RSpec.describe do
490+
around(:context) { }
491+
end
492+
}.to raise_error(ArgumentError, a_string_including("`around(:context)` hooks are not supported"))
494493
end
495494

496-
it 'emits a warning for `around(:context)` defined in `configure`' do
497-
expect(RSpec).to receive(:warn_with).with(a_string_including(
498-
'`around(:context)` hooks are not supported'
499-
))
500-
RSpec.configure do |c|
501-
c.around(:context) { }
502-
end
495+
it 'raises an error for `around(:context)` defined in `configure`' do
496+
expect {
497+
RSpec.configure do |c|
498+
c.around(:context) { }
499+
end
500+
}.to raise_error(ArgumentError, a_string_including("`around(:context)` hooks are not supported"))
503501
end
504502

505503
[:before, :around, :after].each do |type|
506504
it "emits a warning for `#{type}(:suite)` hooks" do
507-
expect(RSpec).to receive(:warn_with).with(a_string_including(
508-
"`#{type}(:suite)` hooks are only supported on the RSpec configuration object."
509-
))
510-
RSpec.describe do
511-
send(type, :suite) { }
512-
end
505+
expect {
506+
RSpec.describe do
507+
send(type, :suite) { }
508+
end
509+
}.to raise_error(ArgumentError, a_string_including(
510+
"`#{type}(:suite)` hooks are only supported on the RSpec configuration object"))
513511
end
514512
end
515513
end

spec/rspec/core/suite_hooks_spec.rb

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,22 @@ module RSpec::Core
6666
end
6767

6868
context "registered on an example group" do
69-
it "is ignored with a clear warning" do
70-
sequence = []
71-
69+
it "raises an error with a clear message" do
7270
expect {
7371
RSpec.describe "Group" do
74-
__send__(registration_method, :suite) { sequence << :suite_hook }
75-
example { sequence << :example }
76-
end.run
77-
}.to change { sequence }.to([:example]).
78-
and output(a_string_including("#{type}(:suite)")).to_stderr
72+
__send__(registration_method, :suite) { }
73+
end
74+
}.to raise_error(a_string_including("#{type}(:suite)"))
7975
end
8076
end
8177

8278
context "registered with metadata" do
83-
it "explicitly warns that the metadata is ignored" do
79+
it "raises an error" do
8480
expect {
8581
RSpec.configure do |c|
8682
c.__send__(registration_method, :suite, :some => :metadata)
8783
end
88-
}.to output(a_string_including(":suite", "metadata")).to_stderr
84+
}.to raise_error(ArgumentError, a_string_including(":suite", "metadata"))
8985
end
9086
end
9187
end
@@ -112,17 +108,6 @@ def define_and_run_example_group(&block)
112108
runner.run err, out
113109
end
114110

115-
it "still runs :suite hooks with metadata even though the metadata is ignored" do
116-
sequence = []
117-
allow(RSpec).to receive(:warn_with)
118-
119-
config.before(:suite, :foo) { sequence << :before_suite }
120-
config.after(:suite, :foo) { sequence << :after_suite }
121-
define_and_run_example_group { sequence << :example_groups }
122-
123-
expect(sequence).to eq([ :before_suite, :example_groups, :after_suite ])
124-
end
125-
126111
it "runs :suite hooks before and after example groups in the correct order" do
127112
sequence = []
128113

0 commit comments

Comments
 (0)