free_mutant/spec/unit/mutant/warning_expectation.rb
Markus Schirp 41d9700473 Refactor runer infrastructure
* Nuke around 800 lock
* Honor LSP with not anymore squeezing something non LSP compatible in
  the same inheritance tree.
* Separate running from result tree.
* Clean up kill logic and early exits on already dead mutations.
* Fix #runnin? smell for reporters.
* Decouple config object from VM state. Makes it serializable to enable
  config loading.
* Fix sequence of global VM events to match PRIOR rspec infects VM with
  gazillions of classes / modules. Thix fixes a startup speed
  degeneration.
* Various fixes to enhance determinism.
* Replace some unneded manual double dispatch with single manual dispatch for
  reporter / runners.
2014-07-05 23:04:38 +00:00

74 lines
2 KiB
Ruby

require 'spec_helper'
describe Mutant::WarningExpectation do
let(:object) { described_class.new(expected_warnings) }
let(:expected_warnings) { [] }
let(:actual_warnings) { [] }
let(:warning_a) { "foo.rb:10: warning: We have a problem!\n" }
let(:warning_b) { "bar.rb:10: warning: We have an other problem!\n" }
describe '#execute' do
subject { object.execute(&block) }
before do
@called = false
end
let(:block) do
lambda do
@called = true
actual_warnings.each(&Kernel.method(:warn))
end
end
it 'executes block' do
expect { subject }.to change { @called }.from(false).to(true)
end
context 'when no warnings occur during block execution' do
context 'and no warnings are expected' do
it_should_behave_like 'a command method'
end
context 'and warnings are expected' do
let(:expected_warnings) { [warning_a] }
before do
expect($stderr).to receive(:puts).with("Expected but missing warnings: #{expected_warnings}")
end
it_should_behave_like 'a command method'
end
end
context 'when warnings occur during block execution' do
let(:actual_warnings) { [warning_a, warning_b] }
context 'and only some no warnings are expected' do
let(:expected_warnings) { [warning_a] }
it 'raises an expectation error' do
expect { subject }.to raise_error(Mutant::WarningExpectation::ExpectationError.new(expected_warnings))
end
end
context 'and all warnings are expected' do
let(:expected_warnings) { [warning_a, warning_b] }
it_should_behave_like 'a command method'
end
context 'and there is an expected warning missing' do
let(:expected_warnings) { [warning_a] }
let(:actual_warnings) { [warning_b] }
it 'raises an expectation error' do
expect { subject }.to raise_error(Mutant::WarningExpectation::ExpectationError.new([warning_b]))
end
end
end
end
end