|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require "helper" |
| 4 | +require "coverage" |
4 | 5 |
|
5 | 6 | describe SimpleCov::Configuration do |
6 | 7 | let(:config_class) do |
|
407 | 408 | end |
408 | 409 | end |
409 | 410 |
|
| 411 | + describe "#adapters (deprecated)" do |
| 412 | + it "warns and returns the profiles registry" do |
| 413 | + result = nil |
| 414 | + stderr = capture_stderr { result = config.adapters } |
| 415 | + expect(result).to equal(config.profiles) |
| 416 | + expect(stderr).to include("[DEPRECATION]") |
| 417 | + expect(stderr).to include("#adapters") |
| 418 | + end |
| 419 | + end |
| 420 | + |
| 421 | + describe "#formatter" do |
| 422 | + it "raises when assigned a falsey value" do |
| 423 | + # `formatter(nil)` is a getter on a defined @formatter; pass a |
| 424 | + # falsey arg directly to take the assignment branch. |
| 425 | + expect { config.formatter(false) }.to raise_error(/No formatter configured/) |
| 426 | + end |
| 427 | + end |
| 428 | + |
| 429 | + describe "#formatters" do |
| 430 | + after do |
| 431 | + config.instance_variable_set(:@formatter, SimpleCov::Formatter::HTMLFormatter) |
| 432 | + end |
| 433 | + |
| 434 | + it "wraps a single formatter as an Array" do |
| 435 | + config.formatter = SimpleCov::Formatter::SimpleFormatter |
| 436 | + expect(config.formatters).to eq([SimpleCov::Formatter::SimpleFormatter]) |
| 437 | + end |
| 438 | + end |
| 439 | + |
| 440 | + describe "#at_exit" do |
| 441 | + around do |example| |
| 442 | + previous = config.instance_variable_get(:@at_exit) |
| 443 | + config.instance_variable_set(:@at_exit, nil) |
| 444 | + example.run |
| 445 | + config.instance_variable_set(:@at_exit, previous) |
| 446 | + end |
| 447 | + |
| 448 | + it "returns a default proc (formats the result) when called with no block while Coverage is running" do |
| 449 | + allow(Coverage).to receive(:running?).and_return(true) |
| 450 | + proc_returned = config.at_exit |
| 451 | + expect(proc_returned).to be_a(Proc) |
| 452 | + end |
| 453 | + |
| 454 | + it "remembers an explicit block across calls" do |
| 455 | + explicit = proc {} |
| 456 | + config.at_exit(&explicit) |
| 457 | + expect(config.at_exit).to equal(explicit) |
| 458 | + end |
| 459 | + |
| 460 | + it "returns a no-op when no session is active and no block is stored" do |
| 461 | + allow(SimpleCov).to receive_messages(result?: false, result: nil) |
| 462 | + allow(Coverage).to receive(:running?).and_return(false) |
| 463 | + config.at_exit.call |
| 464 | + expect(SimpleCov).not_to have_received(:result) |
| 465 | + end |
| 466 | + end |
| 467 | + |
| 468 | + describe "#at_fork" do |
| 469 | + around do |example| |
| 470 | + previous = SimpleCov.instance_variable_get(:@at_fork) |
| 471 | + SimpleCov.instance_variable_set(:@at_fork, nil) |
| 472 | + example.run |
| 473 | + SimpleCov.instance_variable_set(:@at_fork, previous) |
| 474 | + end |
| 475 | + |
| 476 | + it "remembers an explicit block across calls" do |
| 477 | + explicit = proc { |_pid| } |
| 478 | + SimpleCov.at_fork(&explicit) |
| 479 | + expect(SimpleCov.at_fork).to equal(explicit) |
| 480 | + end |
| 481 | + |
| 482 | + it "default lambda re-applies subprocess-friendly config" do |
| 483 | + # Stub the global mutations so this spec doesn't trash the rest |
| 484 | + # of the suite's SimpleCov configuration / restart Coverage. |
| 485 | + allow(SimpleCov).to receive(:command_name) |
| 486 | + allow(SimpleCov).to receive(:print_error_status=) |
| 487 | + allow(SimpleCov).to receive(:formatter) |
| 488 | + allow(SimpleCov).to receive(:minimum_coverage) |
| 489 | + allow(SimpleCov).to receive(:start) |
| 490 | + |
| 491 | + SimpleCov.at_fork.call(12_345) |
| 492 | + |
| 493 | + expect(SimpleCov).to have_received(:command_name).with(/subprocess: 12345/) |
| 494 | + expect(SimpleCov).to have_received(:print_error_status=).with(false) |
| 495 | + expect(SimpleCov).to have_received(:formatter).with(SimpleCov::Formatter::SimpleFormatter) |
| 496 | + expect(SimpleCov).to have_received(:minimum_coverage).with(0) |
| 497 | + expect(SimpleCov).to have_received(:start) |
| 498 | + end |
| 499 | + end |
| 500 | + |
| 501 | + describe "#use_merging" do |
| 502 | + around do |example| |
| 503 | + previous = config.instance_variable_get(:@use_merging) |
| 504 | + config.instance_variable_set(:@use_merging, nil) |
| 505 | + example.run |
| 506 | + config.instance_variable_set(:@use_merging, previous) |
| 507 | + end |
| 508 | + |
| 509 | + it "stores the explicit value when given true" do |
| 510 | + config.use_merging(true) |
| 511 | + expect(config.instance_variable_get(:@use_merging)).to be true |
| 512 | + end |
| 513 | + |
| 514 | + it "stores the explicit value when given false" do |
| 515 | + config.use_merging(false) |
| 516 | + expect(config.instance_variable_get(:@use_merging)).to be false |
| 517 | + end |
| 518 | + |
| 519 | + it "defaults to true when never set" do |
| 520 | + expect(config.use_merging).to be true |
| 521 | + end |
| 522 | + end |
| 523 | + |
410 | 524 | describe "#enable_coverage_for_eval" do |
411 | 525 | context "when the runtime supports eval coverage" do |
412 | 526 | before { allow(config).to receive(:coverage_for_eval_supported?).and_return(true) } |
|
0 commit comments