diff --git a/config/flay.yml b/config/flay.yml index 48be7fe8..884cf67e 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1132 +total_score: 1114 diff --git a/lib/mutant.rb b/lib/mutant.rb index 6b7a3eb8..c0902194 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/subject/method/instance.rb b/lib/mutant/subject/method/instance.rb index e05ec8b0..3f5f341f 100644 --- a/lib/mutant/subject/method/instance.rb +++ b/lib/mutant/subject/method/instance.rb @@ -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 + scope.send(:undef_method, name) self end diff --git a/lib/mutant/warning_expectation.rb b/lib/mutant/warning_expectation.rb deleted file mode 100644 index 71cfbe3c..00000000 --- a/lib/mutant/warning_expectation.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/subject/method/instance_spec.rb b/spec/unit/mutant/subject/method/instance_spec.rb index 544113d7..2d6c0882 100644 --- a/spec/unit/mutant/subject/method/instance_spec.rb +++ b/spec/unit/mutant/subject/method/instance_spec.rb @@ -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' - + it 'undefines method on scope' do + expect { subject }.to change { scope.instance_methods.include?(:foo) }.from(true).to(false) 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 + it_should_behave_like 'a command method' end describe '#source' do diff --git a/spec/unit/mutant/warning_expectation_spec.rb b/spec/unit/mutant/warning_expectation_spec.rb deleted file mode 100644 index 2388f425..00000000 --- a/spec/unit/mutant/warning_expectation_spec.rb +++ /dev/null @@ -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