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

Commit 21ed282

Browse files
Add tests for Callables.bisect
This was previously untested, so I've added coverage to match the other options that generate callable runners. I anticipate extracting this to directly test the callables, but haven't yet decided how best to achieve this.
1 parent 965e2d1 commit 21ed282

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

lib/rspec/core/option_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def parser(options)
6969

7070
parser.on('--bisect[=verbose]', 'Repeatedly runs the suite in order to isolate the failures to the ',
7171
' smallest reproducible case.') do |argument|
72-
options[:bisect] = argument
72+
options[:bisect] = argument || true
7373
options[:runner] = Callables.bisect
7474
end
7575

spec/rspec/core/option_parser_spec.rb

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rspec/core/drb'
2+
require 'rspec/core/bisect/coordinator'
23
require 'rspec/core/project_initializer'
34

45
module RSpec::Core
@@ -391,8 +392,86 @@ def generate_help_text
391392
end
392393
end
393394

394-
describe '--bisect' do
395+
describe "--bisect" do
396+
it "sets the `:bisect` option" do
397+
options = Parser.parse(%w[ --bisect ])
395398

399+
expect(options[:bisect]).to be_truthy
400+
end
401+
402+
it "sets a the `:runner` option with a callable" do
403+
options = Parser.parse(%w[ --bisect ])
404+
405+
expect(options[:runner]).to respond_to(:call)
406+
end
407+
408+
context "when the verbose option is specified" do
409+
it "records this in the options" do
410+
options = Parser.parse(%w[ --bisect=verbose ])
411+
412+
expect(options[:bisect]).to eq("verbose")
413+
end
414+
end
415+
416+
context 'when the runner is called' do
417+
let(:args) { double(:args) }
418+
let(:err) { double(:stderr) }
419+
let(:out) { double(:stdout) }
420+
let(:success) { true }
421+
let(:configuration_options) { double(:options, :args => args) }
422+
423+
before do
424+
allow(RSpec::Core::Bisect::Coordinator).to receive(:bisect_with).and_return(success)
425+
end
426+
427+
it "starts the bisection coordinator" do
428+
options = Parser.parse(%w[ --bisect ])
429+
allow(configuration_options).to receive(:options).and_return(options)
430+
options[:runner].call(configuration_options, err, out)
431+
432+
expect(RSpec::Core::Bisect::Coordinator).to have_received(:bisect_with).with(
433+
args,
434+
RSpec.configuration,
435+
Formatters::BisectProgressFormatter
436+
)
437+
end
438+
439+
context "when the bisection is successful" do
440+
it "returns 0" do
441+
options = Parser.parse(%w[ --bisect ])
442+
allow(configuration_options).to receive(:options).and_return(options)
443+
exit_code = options[:runner].call(configuration_options, err, out)
444+
445+
expect(exit_code).to eq(0)
446+
end
447+
end
448+
449+
context "when the bisection is unsuccessful" do
450+
let(:success) { false }
451+
452+
it "returns 1" do
453+
options = Parser.parse(%w[ --bisect ])
454+
allow(configuration_options).to receive(:options).and_return(options)
455+
exit_code = options[:runner].call(configuration_options, err, out)
456+
457+
expect(exit_code).to eq(1)
458+
end
459+
end
460+
461+
context "and the verbose option is specified" do
462+
it "starts the bisection coordinator with the debug formatter" do
463+
options = Parser.parse(%w[ --bisect=verbose ])
464+
allow(configuration_options).to receive(:options).and_return(options)
465+
options[:runner].call(configuration_options, err, out)
466+
467+
expect(RSpec::Core::Bisect::Coordinator).to have_received(:bisect_with).with(
468+
args,
469+
RSpec.configuration,
470+
Formatters::BisectDebugFormatter
471+
)
472+
end
473+
end
474+
end
396475
end
397476

398477
describe '--profile' do

0 commit comments

Comments
 (0)