[rspec-users] mock_model

Pat Maddox pergesu at gmail.com
Thu Apr 10 13:54:21 EDT 2008

On Thu, Apr 10, 2008 at 10:30 AM, Anthony Broad-Crawford
<abroad-crawford at within3.com> wrote:
> Our company just had an interesting conversation around mock_model and I
> want to ask the same question to this audience.  When creating mock_models
> what is the purpose of passing in the class constant?
> user = mock_model(User)
> To the best that we can tell the method mock_model doesn't actually use the
> class for anything.  Please correct us if we are wrong.  Secondly, we also
> typically after a mock_model stub the necessary properties (attributes) that
> are accessed off of the model.  For example ....
> user = mock_model(User)
> user.stub!(:username) ...
> user.stub!(:password) ....
> Why doesn't mock model interrogate the attributes and generate these mocks
> for me?  Thanks for taking the time to answer.

mock_model does a little bit of stuff for you.  It generates a unique
ID for the object, sets new_record? to false, and gives it an empty
errors array.  Not much else though.

stub_model, available in RSpec trunk, may be more to your liking.  You
can read about it at


More information about the rspec-users mailing list