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

Commit 1484daa

Browse files
committed
Raise an error if bisect_runner is updated too late.
1 parent 34c8d39 commit 1484daa

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

lib/rspec/core/configuration.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def shared_context_metadata_behavior=(value)
413413
# return [Integer]
414414
add_setting :max_displayed_failure_line_count
415415

416-
# @macro add_setting
417416
# Determines which bisect runner implementation gets used to run subsets
418417
# of the suite during a bisection. Your choices are:
419418
#
@@ -433,7 +432,18 @@ def shared_context_metadata_behavior=(value)
433432
# loaded via `--require`.
434433
#
435434
# @return [Symbol]
436-
add_setting :bisect_runner
435+
attr_reader :bisect_runner
436+
def bisect_runner=(value)
437+
if @bisect_runner_class && value != @bisect_runner
438+
raise "`config.bisect_runner = #{value.inspect}` can no longer take " \
439+
"effect as the #{@bisect_runner.inspect} bisect runnner is already " \
440+
"in use. This config setting must be set in a file loaded by a " \
441+
"`--require` option (passed at the CLI or in a `.rspec` file) for " \
442+
"it to have any effect."
443+
end
444+
445+
@bisect_runner = value
446+
end
437447

438448
# @private
439449
# @deprecated Use {#color_mode} = :on, instead of {#color} with {#tty}
@@ -460,6 +470,7 @@ def initialize
460470
@prepend_modules = FilterableItemRepository::QueryOptimized.new(:any?)
461471

462472
@bisect_runner = RSpec::Support::RubyFeatures.fork_supported? ? :fork : :shell
473+
@bisect_runner_class = nil
463474

464475
@before_suite_hooks = []
465476
@after_suite_hooks = []
@@ -1988,16 +1999,18 @@ def on_example_group_definition_callbacks
19881999

19892000
# @private
19902001
def bisect_runner_class
1991-
case bisect_runner
1992-
when :fork
1993-
RSpec::Support.require_rspec_core 'bisect/fork_runner'
1994-
Bisect::ForkRunner
1995-
when :shell
1996-
RSpec::Support.require_rspec_core 'bisect/shell_runner'
1997-
Bisect::ShellRunner
1998-
else
1999-
raise "Unsupported value for `bisect_runner` (#{bisect_runner.inspect}). " \
2000-
"Only `:fork` and `:shell` are supported."
2002+
@bisect_runner_class ||= begin
2003+
case bisect_runner
2004+
when :fork
2005+
RSpec::Support.require_rspec_core 'bisect/fork_runner'
2006+
Bisect::ForkRunner
2007+
when :shell
2008+
RSpec::Support.require_rspec_core 'bisect/shell_runner'
2009+
Bisect::ShellRunner
2010+
else
2011+
raise "Unsupported value for `bisect_runner` (#{bisect_runner.inspect}). " \
2012+
"Only `:fork` and `:shell` are supported."
2013+
end
20012014
end
20022015
end
20032016

spec/rspec/core/configuration_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,22 @@ def metadata_hash(*args)
14701470
config.bisect_runner_class
14711471
}.to raise_error(/Unsupported value for `bisect_runner`/)
14721472
end
1473+
1474+
it 'cannot be changed after the runner is in use' do
1475+
config.bisect_runner = :fork
1476+
config.bisect_runner_class
1477+
1478+
expect {
1479+
config.bisect_runner = :shell
1480+
}.to raise_error(/config.bisect_runner = :shell/)
1481+
end
1482+
1483+
it 'can be set to the same value after the runner is in use' do
1484+
config.bisect_runner = :shell
1485+
config.bisect_runner_class
1486+
1487+
expect { config.bisect_runner = :shell }.not_to raise_error
1488+
end
14731489
end
14741490

14751491
%w[formatter= add_formatter].each do |config_method|

0 commit comments

Comments
 (0)