Drop Subject#public?
* A relict from the days where test selection depended on this information * Kill mutations in Mutation#insert, also very old code.
This commit is contained in:
parent
7144ed8dff
commit
70b4230399
8 changed files with 30 additions and 99 deletions
|
@ -59,15 +59,10 @@ module Mutant
|
|||
|
||||
# Insert mutated node
|
||||
#
|
||||
# FIXME: Cache subject visibility in a better way! Ideally dont mutate it
|
||||
# implicitly. Also subject.public? should NOT be a public interface it
|
||||
# is a detail of method mutations.
|
||||
#
|
||||
# @return [self]
|
||||
#
|
||||
# @api private
|
||||
def insert
|
||||
subject.public?
|
||||
subject.prepare
|
||||
Loader::Eval.call(root, subject)
|
||||
self
|
||||
|
|
|
@ -3,13 +3,6 @@ module Mutant
|
|||
# Abstract base class for method subjects
|
||||
class Method < self
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
# @api private
|
||||
abstract_method :public?
|
||||
|
||||
# Method name
|
||||
#
|
||||
# @return [Expression]
|
||||
|
|
|
@ -7,16 +7,6 @@ module Mutant
|
|||
NAME_INDEX = 0
|
||||
SYMBOL = '#'.freeze
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
# @api private
|
||||
def public?
|
||||
scope.public_method_defined?(name)
|
||||
end
|
||||
memoize :public?
|
||||
|
||||
# Prepare subject for mutation insertion
|
||||
#
|
||||
# @return [self]
|
||||
|
|
|
@ -7,16 +7,6 @@ module Mutant
|
|||
NAME_INDEX = 1
|
||||
SYMBOL = '.'.freeze
|
||||
|
||||
# Test if method is public
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
# @api private
|
||||
def public?
|
||||
scope.singleton_class.public_method_defined?(name)
|
||||
end
|
||||
memoize :public?
|
||||
|
||||
# Prepare subject for mutation insertion
|
||||
#
|
||||
# @return [self]
|
||||
|
|
|
@ -55,7 +55,6 @@ RSpec.describe Mutant::Env do
|
|||
|
||||
before do
|
||||
expect(isolation).to receive(:call).and_yield.and_return(test_result)
|
||||
expect(mutation_subject).to receive(:public?).and_return(true).ordered
|
||||
expect(mutation_subject).to receive(:prepare).and_return(mutation_subject).ordered
|
||||
expect(context).to receive(:root).with(s(:nil)).and_return(wrapped_node).ordered
|
||||
expect(Mutant::Loader::Eval).to receive(:call).with(wrapped_node, mutation_subject).and_return(nil).ordered
|
||||
|
|
|
@ -1,25 +1,45 @@
|
|||
RSpec.describe Mutant::Mutation do
|
||||
|
||||
class TestMutation < Mutant::Mutation
|
||||
SYMBOL = 'test'.freeze
|
||||
end
|
||||
|
||||
let(:object) { TestMutation.new(mutation_subject, Mutant::AST::Nodes::N_NIL) }
|
||||
let(:context) { double('Context') }
|
||||
let(:context) { instance_double(Mutant::Context) }
|
||||
|
||||
let(:mutation_subject) do
|
||||
double(
|
||||
'Subject',
|
||||
instance_double(
|
||||
Mutant::Subject,
|
||||
identification: 'subject',
|
||||
context: context,
|
||||
source: 'original',
|
||||
tests: tests
|
||||
context: context,
|
||||
source: 'original'
|
||||
)
|
||||
end
|
||||
|
||||
let(:test_a) { double('Test A') }
|
||||
let(:test_b) { double('Test B') }
|
||||
let(:tests) { [test_a, test_b] }
|
||||
let(:test_a) { instance_double(Mutant::Test) }
|
||||
let(:test_b) { instance_double(Mutant::Test) }
|
||||
|
||||
describe '#insert' do
|
||||
subject { object.insert }
|
||||
|
||||
let(:root_node) { s(:foo) }
|
||||
|
||||
before do
|
||||
expect(context).to receive(:root)
|
||||
.with(object.node)
|
||||
.and_return(root_node)
|
||||
|
||||
expect(mutation_subject).to receive(:prepare)
|
||||
.ordered
|
||||
.and_return(mutation_subject)
|
||||
|
||||
expect(Mutant::Loader::Eval).to receive(:call)
|
||||
.ordered
|
||||
.with(root_node, mutation_subject)
|
||||
.and_return(Mutant::Loader::Eval)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
end
|
||||
|
||||
describe '#code' do
|
||||
subject { object.code }
|
||||
|
|
|
@ -59,34 +59,6 @@ RSpec.describe Mutant::Subject::Method::Instance do
|
|||
|
||||
it { should eql("def foo\nend") }
|
||||
end
|
||||
|
||||
describe '#public?' do
|
||||
subject { object.public? }
|
||||
|
||||
context 'when method is public' do
|
||||
it { should be(true) }
|
||||
end
|
||||
|
||||
context 'when method is private' do
|
||||
before do
|
||||
scope.class_eval do
|
||||
private :foo
|
||||
end
|
||||
end
|
||||
|
||||
it { should be(false) }
|
||||
end
|
||||
|
||||
context 'when method is protected' do
|
||||
before do
|
||||
scope.class_eval do
|
||||
protected :foo
|
||||
end
|
||||
end
|
||||
|
||||
it { should be(false) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe Mutant::Subject::Method::Instance::Memoized do
|
||||
|
|
|
@ -50,32 +50,4 @@ RSpec.describe Mutant::Subject::Method::Singleton do
|
|||
|
||||
it { should eql("def self.foo\nend") }
|
||||
end
|
||||
|
||||
describe '#public?' do
|
||||
subject { object.public? }
|
||||
|
||||
context 'when method is public' do
|
||||
it { should be(true) }
|
||||
end
|
||||
|
||||
context 'when method is private' do
|
||||
before do
|
||||
scope.class_eval do
|
||||
private_class_method :foo
|
||||
end
|
||||
end
|
||||
|
||||
it { should be(false) }
|
||||
end
|
||||
|
||||
context 'when method is protected' do
|
||||
before do
|
||||
class << scope
|
||||
protected :foo
|
||||
end
|
||||
end
|
||||
|
||||
it { should be(false) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue