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

Commit 9d54bbb

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

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.1...master)
3+
4+
Bug Fixes:
5+
6+
* Emit a warning when `around` hook is used with `:context` scope
7+
(Phil Pirozhkov, #2687)
8+
19
### 3.9.1 / 2019-12-28
210
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.0...v3.9.1)
311

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).to receive(:warn_with).with(a_string_including(
498+
'`around(:context)` hooks are not supported'
499+
))
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)