Add specs for Mutation#insert

This commit is contained in:
Markus Schirp 2014-11-17 20:31:12 +00:00
parent 584e06d5f2
commit 375059519a
5 changed files with 28 additions and 19 deletions

View file

@ -1,3 +1,3 @@
--- ---
threshold: 18 threshold: 18
total_score: 1121 total_score: 1119

View file

@ -13,14 +13,13 @@ module Mutant
# @api private # @api private
# #
def call def call
subject.prepare
eval( eval(
source, source,
TOPLEVEL_BINDING, TOPLEVEL_BINDING,
subject.source_path.to_s, subject.source_path.to_s,
subject.source_line subject.source_line
) )
nil self
end end
private private

View file

@ -7,17 +7,6 @@ module Mutant
CODE_DELIMITER = "\0".freeze CODE_DELIMITER = "\0".freeze
CODE_RANGE = (0..4).freeze CODE_RANGE = (0..4).freeze
# Return mutated root node
#
# @return [Parser::AST::Node]
#
# @api private
#
def root
subject.root(node)
end
memoize :root
# Insert mutated node # Insert mutated node
# #
# FIXME: Cache subject visibility in a better way! Ideally dont mutate it # FIXME: Cache subject visibility in a better way! Ideally dont mutate it
@ -30,6 +19,7 @@ module Mutant
# #
def insert def insert
subject.public? subject.public?
subject.prepare
Loader::Eval.call(root, subject) Loader::Eval.call(root, subject)
self self
end end
@ -102,6 +92,16 @@ module Mutant
end end
memoize :sha1 memoize :sha1
# Return mutated root node
#
# @return [Parser::AST::Node]
#
# @api private
#
def root
subject.root(node)
end
# Evil mutation that should case mutations to fail tests # Evil mutation that should case mutations to fail tests
class Evil < self class Evil < self

View file

@ -10,10 +10,6 @@ RSpec.describe Mutant::Loader::Eval, '.call' do
double('Subject', source_path: path, source_line: line) double('Subject', source_path: path, source_line: line)
end end
before do
expect(mutation_subject).to receive(:prepare).and_return(mutation_subject)
end
let(:source) do let(:source) do
<<-RUBY <<-RUBY
class SomeNamespace class SomeNamespace

View file

@ -6,7 +6,6 @@ RSpec.describe Mutant::Mutation do
let(:object) { TestMutation.new(mutation_subject, Mutant::AST::Nodes::N_NIL) } let(:object) { TestMutation.new(mutation_subject, Mutant::AST::Nodes::N_NIL) }
let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') } let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') }
let(:node) { double('Node') }
describe '#code' do describe '#code' do
subject { object.code } subject { object.code }
@ -24,6 +23,21 @@ RSpec.describe Mutant::Mutation do
it_should_behave_like 'an idempotent method' it_should_behave_like 'an idempotent method'
end end
describe '#insert' do
subject { object.insert }
let(:wrapped_node) { double('Wrapped Node') }
before do
expect(mutation_subject).to receive(:public?).ordered.and_return(true)
expect(mutation_subject).to receive(:prepare).ordered
expect(mutation_subject).to receive(:root).ordered.with(s(:nil)).and_return(wrapped_node)
expect(Mutant::Loader::Eval).to receive(:call).ordered.with(wrapped_node, mutation_subject).and_return(nil)
end
it_should_behave_like 'a command method'
end
describe '#source' do describe '#source' do
subject { object.source } subject { object.source }