Topic: rSpec and Mocha

Anyone out there using rSpec and mocha to mock/stub?

I've been playing around with mocha instead of rSpec's built-in system for mocking/stubbing, and I have just two quick questions:

What is the mocha equivalent of:

@post = mock_model(Post, :to_param => "1")


What is the moch equivalent of:


If anyone could help me out, I would really appreciate it.

Re: rSpec and Mocha

I don't use mocha but I think you can setup a mock of a model in three ways:

Classic way:

@post = mock("post")

Using fixtures
mock_model :post

Using the ActiveRecord Object
@post =

Honestly the only one that I'd use would be the first way of doing it.
I'm sure you could wrap the first way in a method.

I think for expectations its


Why did you choose to use Mocha over RSpec's mocking/stubbing?

Last edited by OmenKing (2007-10-07 23:10:16)

Re: rSpec and Mocha

Thank you for providing a simple and easy to understand overview of mocking and stubbing.  That is perhaps what I needed most of all, as the whole thing still confuses me big time.