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

Emit a warning for around(:context) #2687

Merged
merged 1 commit into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Development
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.1...master)

Bug Fixes:

* Emit a warning when `around` hook is used with `:context` scope
(Phil Pirozhkov, #2687)

### 3.9.1 / 2019-12-28
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.9.0...v3.9.1)

Expand Down
5 changes: 5 additions & 0 deletions lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ def register(prepend_or_append, position, *args, &block)
"`#{position}(:suite)` hook, registered on an example " \
"group, will be ignored."
return
elsif scope == :context && position == :around
# TODO: consider making this an error in RSpec 4. For SemVer reasons,
# we are only warning in RSpec 3.
RSpec.warn_with "WARNING: `around(:context)` hooks are not supported and " \
"behave like `around(:example)."
end

hook = HOOK_TYPES[position][scope].new(block, options)
Expand Down
29 changes: 29 additions & 0 deletions spec/rspec/core/hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,34 @@ def yielder
:hooks
])
end

it 'emits a warning for `around(:context)`' do
expect(RSpec).to receive(:warn_with).with(a_string_including(
'`around(:context)` hooks are not supported'
))
RSpec.describe do
around(:context) { }
end
end

it 'emits a warning for `around(:context)` defined in `configure`' do
expect(RSpec).to receive(:warn_with).with(a_string_including(
'`around(:context)` hooks are not supported'
))
RSpec.configure do |c|
c.around(:context) { }
end
end

[:before, :around, :after].each do |type|
it "emits a warning for `#{type}(:suite)` hooks" do
expect(RSpec).to receive(:warn_with).with(a_string_including(
"`#{type}(:suite)` hooks are only supported on the RSpec configuration object."
))
RSpec.describe do
send(type, :suite) { }
end
end
end
end
end