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