Remove warning expectations
* Warnings do not disturb master output anymore as we redirect stderr of children to dev null. So the main reason for adding this feature is gone. BTW Its planned to capture the stderr of childrens later. * Warning expectations do not work very well under zombification as line numbers change.
This commit is contained in:
parent
f54c7c42cf
commit
ae7284f39a
6 changed files with 5 additions and 172 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1132
|
||||
total_score: 1114
|
||||
|
|
|
@ -103,7 +103,6 @@ require 'mutant/ast/meta'
|
|||
require 'mutant/cache'
|
||||
require 'mutant/delegator'
|
||||
require 'mutant/warning_filter'
|
||||
require 'mutant/warning_expectation'
|
||||
require 'mutant/require_highjack'
|
||||
require 'mutant/isolation'
|
||||
require 'mutant/mutator'
|
||||
|
|
|
@ -7,10 +7,6 @@ module Mutant
|
|||
NAME_INDEX = 0
|
||||
SYMBOL = '#'.freeze
|
||||
|
||||
# A list of methods that will warn when they are undefined
|
||||
WARN_METHODS_UNDEFINED =
|
||||
RUBY_ENGINE.eql?('ruby') ? [:initialize, :__send__, :object_id].freeze : EMPTY_ARRAY
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [Boolean]
|
||||
|
@ -22,8 +18,6 @@ module Mutant
|
|||
end
|
||||
memoize :public?
|
||||
|
||||
LINE_INCREMENT = defined?(Zombie) ? -11 : 5
|
||||
|
||||
# Prepare subject for mutation insertion
|
||||
#
|
||||
# @return [self]
|
||||
|
@ -31,15 +25,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def prepare
|
||||
expected_warnings =
|
||||
if WARN_METHODS_UNDEFINED.include?(name)
|
||||
["#{__FILE__}:#{__LINE__ + LINE_INCREMENT}: warning: undefining `#{name}' may cause serious problems\n"]
|
||||
else
|
||||
EMPTY_ARRAY
|
||||
end
|
||||
WarningExpectation.new(expected_warnings).execute do
|
||||
scope.send(:undef_method, name)
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
module Mutant
|
||||
# A class to expect some warning message raising on absence of unexpected warnings
|
||||
class WarningExpectation
|
||||
include Adamantium::Flat, Concord.new(:expected)
|
||||
|
||||
# Error raised on expectation miss
|
||||
class ExpectationError < RuntimeError
|
||||
include Concord.new(:unexpected, :expected)
|
||||
|
||||
# Return exception message
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def message
|
||||
"Unexpected warnings: #{unexpected.inspect}, expected: #{expected.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
# Execute blocks with warning expectations
|
||||
#
|
||||
# @return [self]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def execute(&block)
|
||||
warnings = WarningFilter.use do
|
||||
block.call
|
||||
end
|
||||
|
||||
missing = expected - warnings
|
||||
unexpected = warnings - expected
|
||||
|
||||
if unexpected.any?
|
||||
fail ExpectationError.new(unexpected, expected)
|
||||
end
|
||||
|
||||
if missing.any?
|
||||
$stderr.puts("Expected but missing warnings: #{missing}")
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
end # WarningExpectation
|
||||
end # Mutant
|
|
@ -48,36 +48,11 @@ RSpec.describe Mutant::Subject::Method::Instance do
|
|||
|
||||
subject { object.prepare }
|
||||
|
||||
context 'on non initialize methods' do
|
||||
|
||||
it 'undefines method on scope' do
|
||||
expect { subject }.to change { scope.instance_methods.include?(:foo) }.from(true).to(false)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
|
||||
end
|
||||
|
||||
context 'on initialize method' do
|
||||
|
||||
let(:node) do
|
||||
s(:def, :initialize, s(:args))
|
||||
end
|
||||
|
||||
it 'does not write warnings' do
|
||||
warnings = Mutant::WarningFilter.use do
|
||||
subject
|
||||
end
|
||||
expect(warnings).to eql([])
|
||||
end
|
||||
|
||||
it 'undefines method on scope' do
|
||||
subject
|
||||
expect { scope.new }.to raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#source' do
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
RSpec.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([warning_b], 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], expected_warnings))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe Mutant::WarningExpectation::ExpectationError do
|
||||
describe '#message' do
|
||||
subject { described_class.new(['unexpected-a'], ['expected-b']).message }
|
||||
|
||||
it { should eql('Unexpected warnings: ["unexpected-a"], expected: ["expected-b"]') }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue