Есть такой вот код:
def index
@my_model = MyModel.find_by_id(params[:id])
attrs = @my_model.attrs.find(:all)
for attr in atts do
attr.do_somesing
end
end
Проблемы начинаются с написанием тестов на rspec`е:
describe MyController
before(:all)
@my_model = mock(MyModel)
@attr = mock(Attr)
MyModel.stub!(:find_by_id).and_return(@my_model)
@my_model.stub!(:attrs).and_return(@attr)
@attr.stub!(:find).and_return(@attr)
end
it 'must be valid'
@attr.should_receive(:do_somesing).once.with(no_args).and_return(false)
end
end
На что rspec пишет:
Spec::Mocks::MockExpectationError in 'MyController must be valid'
Mock 'Attr' received unexpected message :each with (no args)
Как можно сказать rspec`у не использовать mocking для метода each?