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

Commit 91203d3

Browse files
committed
Raise on usage of metadata on suite-level scopes
1 parent e5a6b5c commit 91203d3

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Breaking Changes:
1010
and remove the configuration option. (Phil Pirozhkov, #2834)
1111
* Remove `run_all_when_everything_filtered` configuration option. (Phil Pirozhkov, #2845)
1212
* Raise on unsupported hook scope usage. (Phil Pirozhkov, #2849)
13+
* Raise on usage of metadata on suite-level scopes. (Phil Pirozhkov, #2849)
1314

1415
Enhancements:
1516

lib/rspec/core/configuration.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,7 @@ def handle_suite_hook(scope, meta)
19901990
return nil unless scope == :suite
19911991

19921992
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 " \
1993+
raise ArgumentError, "WARNING: `:suite` hooks do not support metadata since " \
19961994
"they apply to the suite as a whole rather than " \
19971995
"any individual example or example group that has metadata. " \
19981996
"The metadata you have provided (#{meta.inspect}) will be ignored."

spec/rspec/core/suite_hooks_spec.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ module RSpec::Core
7676
end
7777

7878
context "registered with metadata" do
79-
it "explicitly warns that the metadata is ignored" do
79+
it "raises an error" do
8080
expect {
8181
RSpec.configure do |c|
8282
c.__send__(registration_method, :suite, :some => :metadata)
8383
end
84-
}.to output(a_string_including(":suite", "metadata")).to_stderr
84+
}.to raise_error(ArgumentError, a_string_including(":suite", "metadata"))
8585
end
8686
end
8787
end
@@ -108,17 +108,6 @@ def define_and_run_example_group(&block)
108108
runner.run err, out
109109
end
110110

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

0 commit comments

Comments
 (0)