Add specs for Mutation#insert
This commit is contained in:
parent
584e06d5f2
commit
375059519a
5 changed files with 28 additions and 19 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1121
|
||||
total_score: 1119
|
||||
|
|
|
@ -13,14 +13,13 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def call
|
||||
subject.prepare
|
||||
eval(
|
||||
source,
|
||||
TOPLEVEL_BINDING,
|
||||
subject.source_path.to_s,
|
||||
subject.source_line
|
||||
)
|
||||
nil
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -7,17 +7,6 @@ module Mutant
|
|||
CODE_DELIMITER = "\0".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
|
||||
#
|
||||
# FIXME: Cache subject visibility in a better way! Ideally dont mutate it
|
||||
|
@ -30,6 +19,7 @@ module Mutant
|
|||
#
|
||||
def insert
|
||||
subject.public?
|
||||
subject.prepare
|
||||
Loader::Eval.call(root, subject)
|
||||
self
|
||||
end
|
||||
|
@ -102,6 +92,16 @@ module Mutant
|
|||
end
|
||||
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
|
||||
class Evil < self
|
||||
|
||||
|
|
|
@ -10,10 +10,6 @@ RSpec.describe Mutant::Loader::Eval, '.call' do
|
|||
double('Subject', source_path: path, source_line: line)
|
||||
end
|
||||
|
||||
before do
|
||||
expect(mutation_subject).to receive(:prepare).and_return(mutation_subject)
|
||||
end
|
||||
|
||||
let(:source) do
|
||||
<<-RUBY
|
||||
class SomeNamespace
|
||||
|
|
|
@ -6,7 +6,6 @@ RSpec.describe Mutant::Mutation do
|
|||
|
||||
let(:object) { TestMutation.new(mutation_subject, Mutant::AST::Nodes::N_NIL) }
|
||||
let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') }
|
||||
let(:node) { double('Node') }
|
||||
|
||||
describe '#code' do
|
||||
subject { object.code }
|
||||
|
@ -24,6 +23,21 @@ RSpec.describe Mutant::Mutation do
|
|||
it_should_behave_like 'an idempotent method'
|
||||
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
|
||||
subject { object.source }
|
||||
|
||||
|
|
Loading…
Reference in a new issue