any_instance with rspec

Hi,

I really need to use any_instance - which is a Mocha feature with rspec. I really can't get around it. In "The Rails Way", the author says "It is possible to use Mocha together with RSpec...". How?

Thanks, Tiberiu

Look in spec/spec_helper.rb, where you can tell RSpec which mock framework you'd like to use. For reference, the one on my current project looks like this:

  # ...   # == Mock Framework

Hi Craig,

Thanks so much. The project was started last year and I didn't even have those lines in my spec_helper.rb. Serves me right for not reading all the docs.

Tiberiu

You're welcome. Note that with each new release of RSpec, you should re-run the rspec generation command. See: http://rspec.info/upgrade.html . Of course, before you do, you might want to save a copy of spec/spec_helper.rb and spec/spec.opts so that you can reapply your changes after they're regenerated.

Regards, Craig

Cool. Thanks.

If you look at Ryan's cast number 71 he uses any_instance to stub out valid? on active record - this allows you to make sure, for example, to just go to the behaviour of the controller and use stuff like assigns[:fred].value == 'whatever'.

I'm really struggling with overriding new and returning a prebuilt object because I can't check the low-level assign on a multi-model controller.

Yeah, ok, I can say

assigns[:claim].should == @new_claim

But I wanted to check the fields in the claim and the address that belongs to it are all being hit.

Can't face learning mocha - no time right now.