2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-07-30 21:40:49 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-08-15 21:13:05 +02:00
|
|
|
describe Mutant::Mutator, '#emit' do
|
2012-12-06 21:30:28 +01:00
|
|
|
subject { object.send(:emit, generated) }
|
2012-07-30 21:40:49 +02:00
|
|
|
|
|
|
|
class Block
|
2013-07-28 12:16:45 -07:00
|
|
|
attr_reader :arguments
|
2012-07-30 21:40:49 +02:00
|
|
|
|
|
|
|
def called?
|
|
|
|
defined?(@arguments)
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(*arguments)
|
|
|
|
@arguments = arguments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-24 22:10:40 +02:00
|
|
|
let(:object) { class_under_test.new(input, parent, block) }
|
|
|
|
let(:block) { Block.new }
|
|
|
|
let(:input) { :input }
|
|
|
|
let(:parent) { :parent }
|
2012-07-30 21:40:49 +02:00
|
|
|
|
2012-07-31 04:00:05 +02:00
|
|
|
let(:class_under_test) do
|
|
|
|
Class.new(described_class) do
|
|
|
|
def dispatch
|
2013-07-28 12:16:45 -07:00
|
|
|
# noop
|
2012-07-31 04:00:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
context 'with generated that is not equal to input' do
|
|
|
|
let(:generated) { :generated }
|
2012-07-30 21:40:49 +02:00
|
|
|
|
|
|
|
it 'should call block' do
|
|
|
|
subject
|
|
|
|
block.should be_called
|
|
|
|
end
|
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
it 'should call block with generated' do
|
2012-07-30 21:40:49 +02:00
|
|
|
subject
|
2012-12-06 21:30:28 +01:00
|
|
|
block.arguments.should eql([generated])
|
2012-07-30 21:40:49 +02:00
|
|
|
end
|
|
|
|
end
|
2012-07-31 04:10:37 +02:00
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
context 'with generated object that is equal to input' do
|
|
|
|
let(:generated) { input }
|
2012-07-30 21:40:49 +02:00
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
it 'should not call block' do
|
2012-07-30 21:40:49 +02:00
|
|
|
subject
|
|
|
|
block.should_not be_called
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|