Re: [rspec-users] Stubbing Observers in rails?
Mocha has an any_instance method that does this and flexmock has a new_instances method that does the same. I tried patching the rspec mocking framework to do this and got it working for new instances, but I couldn't get it working with passing arguments to the initialize method. That and the internals of the rspec mocking framework scare the bejeesus out of me. So I just use mocha for mocking and call it a day. Cheers, Carl On Jul 31, 2007, at 11:07 AM, David Chelimsky wrote: > On 7/31/07, Doug Cole <[EMAIL PROTECTED]> wrote: >> If I'm not mistaken those stub them out always - I'd like to be >> able to stub >> them out for most tests, but I would like to have them around when >> I want to >> write tests for the observers themselves! I imagine this is a >> fairly common >> use case for Observers and testing. > > There's an RFE for stubbing all instances: > > http://rubyforge.org/tracker/? > func=detail&group_id=797&aid=6791&atid=3152 > > It's been there for a while. This is very low priority for me, so if > you're interested in seeing it happen your best bet would be to submit > a patch. > > Alternatively, I *think* that mocha supports this, so you could use > mocha with RSpec instead of the rspec mock framework. > > Cheers, > David > >> >> >>> If you're looking to stub all instances, why not use (what) Rails >>> (calls) >> mocks? >> >> ___ >> rspec-users mailing list >> rspec-users@rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Stubbing Observers in rails?
On 7/31/07, Doug Cole <[EMAIL PROTECTED]> wrote: > If I'm not mistaken those stub them out always - I'd like to be able to stub > them out for most tests, but I would like to have them around when I want to > write tests for the observers themselves! I imagine this is a fairly common > use case for Observers and testing. There's an RFE for stubbing all instances: http://rubyforge.org/tracker/?func=detail&group_id=797&aid=6791&atid=3152 It's been there for a while. This is very low priority for me, so if you're interested in seeing it happen your best bet would be to submit a patch. Alternatively, I *think* that mocha supports this, so you could use mocha with RSpec instead of the rspec mock framework. Cheers, David > > > >If you're looking to stub all instances, why not use (what) Rails (calls) > mocks? > > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Stubbing Observers in rails?
If I'm not mistaken those stub them out always - I'd like to be able to stub them out for most tests, but I would like to have them around when I want to write tests for the observers themselves! I imagine this is a fairly common use case for Observers and testing. >If you're looking to stub all instances, why not use (what) Rails (calls) mocks? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Stubbing Observers in rails?
On 7/30/07, Doug Cole <[EMAIL PROTECTED]> wrote: > In most of my tests I'd like to be able to stub out the observers for my > models, but I'm not sure the best way to do this. I doesn't look like there > is a way to stub all instance methods, and I don't seem to be able to stub > early enough to stub out the observer as it's instantiated. I can think of > several hackish ways to get around it, but I was wondering if anyone could > suggest a good solution? Thanks! If you're looking to stub all instances, why not use (what) Rails (calls) mocks? > > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Stubbing Observers in rails?
In most of my tests I'd like to be able to stub out the observers for my models, but I'm not sure the best way to do this. I doesn't look like there is a way to stub all instance methods, and I don't seem to be able to stub early enough to stub out the observer as it's instantiated. I can think of several hackish ways to get around it, but I was wondering if anyone could suggest a good solution? Thanks! ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users