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")

second...

What is the moch equivalent of:

Project.should_receive(....)

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")
@post.stub!(:is_a?).and_return(true)
@post.stub!(:new_record?).and_return(false)
@post.stub!(:id).and_return(rand(1000))
@post.stub!(:to_param).and_return(1)

Using fixtures
mock_model :post
@post..stub!(:to_param).and_return(1)

Using the ActiveRecord Object
@post = Post.new()
@post.stub!(:to_param).and_return(1)

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

Project.expects(...)

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.