Hi Raul,
I was chatting with some of my colleagues this morning and we came up
with the idea of providing after_build and after_create callbacks in
the factory. Taking your example, you'd do the following:
Factory :user_with_baz_web_service_account, :class => User do |f|
f.foo 'bar'
...
f.after_build do |user|
user.stubs(:create_web_service_account).returns('baz')
end
end
Then if you do Factory(:user_with_baz_web_service_account).create you
get yourself a user that has a stubbed out
create_web_service_account. So, rather than baking stubbing or
mocking into Factories directly, we've just provided hooks that can be
run after the object is built or after it is created where you can do
whatever you want.
I'm sure there are limitations to this, but it might be what you are
looking for. I've made my changes availble on github if you are
interested:
http://github.com/h-lame/factory_girl/tree/master
I'd also love to hear what anyone else thinks of such a solution.
Cheers,
Muz