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

Commit aa884c3

Browse files
committed
Emit a warning for around(:context)
fixes #2486
1 parent 1174cc5 commit aa884c3

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Bug Fixes:
66
* Prevent bisect command from blocking when number of specs exceeds file
77
descriptor limit on OSX or Linux. (Benoit Tigeot, #2669)
88
* Prevent warnings being issued on Ruby 2.7.0. (Jon Rowe, #2680)
9+
* Emit a warning when `around` hook is used with `:context` scope
10+
(Phil Pirozhkov, #2687)
911

1012
### 3.9.0 / 2019-10-07
1113
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.8.2...v3.9.0)

lib/rspec/core/hooks.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ def register(prepend_or_append, position, *args, &block)
448448
"`#{position}(:suite)` hook, registered on an example " \
449449
"group, will be ignored."
450450
return
451+
elsif scope == :context && position == :around
452+
# TODO: consider making this an error in RSpec 4. For SemVer reasons,
453+
# we are only warning in RSpec 3.
454+
RSpec.warn_with "WARNING: `around(:context)` hooks are not supported and " \
455+
"behave like `around(:example)."
451456
end
452457

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

spec/rspec/core/hooks_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,5 +492,34 @@ def yielder
492492
:hooks
493493
])
494494
end
495+
496+
it 'emits a warning for `around(:context)`' do
497+
expect(RSpec)
498+
.to receive(:warn_with)
499+
.with(a_string_including('`around(:context)` hooks are not supported'))
500+
RSpec.describe do
501+
around(:context) { }
502+
end
503+
end
504+
505+
it 'emits a warning for `around(:context)` defined in `configure`' do
506+
expect(RSpec).to receive(:warn_with).with(a_string_including(
507+
'`around(:context)` hooks are not supported'
508+
))
509+
RSpec.configure do |c|
510+
c.around(:context) { }
511+
end
512+
end
513+
514+
[:before, :around, :after].each do |type|
515+
it "emits a warning for `#{type}(:suite)` hooks" do
516+
expect(RSpec).to receive(:warn_with).with(a_string_including(
517+
"`#{type}(:suite)` hooks are only supported on the RSpec configuration object."
518+
))
519+
RSpec.describe do
520+
send(type, :suite) { }
521+
end
522+
end
523+
end
495524
end
496525
end

0 commit comments

Comments
 (0)