2012-07-26 13:25:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-08-01 12:34:03 -04:00
|
|
|
describe Mutant::Subject, '#each' do
|
2012-07-26 13:25:23 -04:00
|
|
|
subject { object.each { |item| yields << item } }
|
|
|
|
|
2013-01-13 16:32:03 -05:00
|
|
|
let(:class_under_test) do
|
|
|
|
Class.new(described_class)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:object) { class_under_test.new(context, ast) }
|
|
|
|
let(:root) { mock('Root Node') }
|
|
|
|
let(:ast) { mock('Node') }
|
|
|
|
let(:context) { mock('Context', :root => root) }
|
|
|
|
let(:mutant) { mock('Mutant') }
|
|
|
|
let(:mutation) { mock('Mutation') }
|
|
|
|
let(:yields) { [] }
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
before do
|
2012-08-15 22:10:54 -04:00
|
|
|
Mutant::Mutator.stub(:each).with(ast).and_yield(mutant).and_return(Mutant::Mutator)
|
|
|
|
Mutant::Mutation.stub(:new => mutation)
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
|
|
|
|
2012-08-01 12:19:12 -04:00
|
|
|
it_should_behave_like 'an #each method'
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-07-27 16:39:31 -04:00
|
|
|
it 'should initialize mutator with ast' do
|
2012-07-30 22:00:05 -04:00
|
|
|
Mutant::Mutator.should_receive(:each).with(ast).and_yield(mutation).and_return(Mutant::Mutator)
|
2012-07-27 16:39:31 -04:00
|
|
|
subject
|
|
|
|
end
|
2012-07-26 13:25:23 -04:00
|
|
|
|
|
|
|
it 'should yield mutations' do
|
|
|
|
expect { subject }.to change { yields.dup }.from([]).to([mutation])
|
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
|
|
|
|
it 'should initialize mutation' do
|
|
|
|
Mutant::Mutation.should_receive(:new).with(object, mutant).and_return(mutation)
|
|
|
|
subject
|
|
|
|
end
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|