|
1 | 1 | require 'rspec/core/drb'
|
| 2 | +require 'rspec/core/bisect/coordinator' |
2 | 3 | require 'rspec/core/project_initializer'
|
3 | 4 |
|
4 | 5 | module RSpec::Core
|
@@ -391,8 +392,86 @@ def generate_help_text
|
391 | 392 | end
|
392 | 393 | end
|
393 | 394 |
|
394 |
| - describe '--bisect' do |
| 395 | + describe "--bisect" do |
| 396 | + it "sets the `:bisect` option" do |
| 397 | + options = Parser.parse(%w[ --bisect ]) |
395 | 398 |
|
| 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 |
396 | 475 | end
|
397 | 476 |
|
398 | 477 | describe '--profile' do
|
|
0 commit comments