2012-07-30 16:18:00 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-07-30 22:10:37 -04:00
|
|
|
describe Mutant::Mutator, '#emit_new' do
|
2012-07-30 22:00:05 -04:00
|
|
|
subject { object.send(:emit_new) { node } }
|
2012-07-30 16:18:00 -04:00
|
|
|
|
|
|
|
class Block
|
|
|
|
attr_reader :arguments
|
|
|
|
|
|
|
|
def called?
|
|
|
|
defined?(@arguments)
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(*arguments)
|
|
|
|
@arguments = arguments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-30 22:10:37 -04:00
|
|
|
let(:object) { class_under_test.new(wrapped_node, block) }
|
2012-07-30 22:00:05 -04:00
|
|
|
let(:block) { Block.new }
|
|
|
|
let(:wrapped_node) { '"foo"'.to_ast }
|
|
|
|
|
|
|
|
let(:class_under_test) do
|
|
|
|
Class.new(described_class) do
|
|
|
|
def dispatch
|
|
|
|
#noop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-30 16:18:00 -04:00
|
|
|
|
|
|
|
context 'when new AST is generated' do
|
|
|
|
let(:node) { '"bar"'.to_ast }
|
|
|
|
|
|
|
|
it 'should call block' do
|
|
|
|
subject
|
|
|
|
block.should be_called
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should call block with node' do
|
|
|
|
subject
|
|
|
|
block.arguments.should eql([node])
|
|
|
|
end
|
|
|
|
end
|
2012-07-30 22:10:37 -04:00
|
|
|
|
2012-07-30 16:18:00 -04:00
|
|
|
context 'when new AST could not be generated' do
|
|
|
|
let(:node) { '"foo"'.to_ast }
|
|
|
|
|
|
|
|
it 'should raise error' do
|
2012-07-30 22:10:37 -04:00
|
|
|
expect { subject }.to raise_error(RuntimeError, 'New AST could not be generated after 3 attempts')
|
2012-07-30 16:18:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|