Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
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
19 changes: 19 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,25 @@ def warnings?
$VERBOSE
end

# @private
RAISE_ERROR_WARNING_NOTIFIER = lambda { |message| raise message }

# Turns warnings into errors. This can be useful when
# you want RSpec to run in a 'strict' no warning situation.
#
# @example
#
# RSpec.configure do |rspec|
# rspec.raise_on_warning = true
# end
def raise_on_warning=(value)
if value
RSpec::Support.warning_notifier = RAISE_ERROR_WARNING_NOTIFIER
else
RSpec::Support.warning_notifier = RSpec::Support::DEFAULT_WARNING_NOTIFIER
end
end

# Exposes the current running example via the named
# helper method. RSpec 2.x exposed this via `example`,
# but in RSpec 3.0, the example is instead exposed via
Expand Down
21 changes: 21 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,27 @@ def strategy.order(list)
end
end

describe '#raise_on_warning=(value)' do
around do |example|
original_setting = RSpec::Support.warning_notifier
example.run
RSpec::Support.warning_notifier = original_setting
end

it 'causes warnings to raise errors when true' do
config.raise_on_warning = true
expect {
RSpec.warning 'All hell breaks loose'
}.to raise_error a_string_including('WARNING: All hell breaks loose')
end

it 'causes warnings to default to warning when false' do
config.raise_on_warning = false
expect_warning_with_call_site(__FILE__, __LINE__ + 1)
RSpec.warning 'doesnt raise'
end
end

describe "#raise_errors_for_deprecations!" do
it 'causes deprecations to raise errors rather than printing to the deprecation stream' do
config.deprecation_stream = stream = StringIO.new
Expand Down