Almost every spec file I come accross I end up writing stuff like:
before :each do
@cimg = Factory.build :cimg_valid
@cimg.stub(:validate_img).and_retu
A factory should produce "real world" objects therefore it's a bad practice (and error prone) to change behaviour (i.e. stub) in a factory.
You can do
let(:user) instance_double(User, FactoryGirl.attributes_for(:user))
before do
allow(user).to receive(:something).and_return('something')
end
and if your before
clause gets too big you may want to extract it to a separate method or create a mock child class that overrides methods you want to stub.