[rspec-users] testing a post to a controller's create action

Patrick J. Collins patrick at collinatorstudios.com
Sun Nov 20 03:46:43 EST 2011

> I haven't used ActiveRecord in quite awhile (been using MongoDB), but it looks like you cannot instantiate a record with attributes that don't exist. I think you have two options here:
> 1.) Only use valid attributes in your params.
> 2.) Add `with` to your stub to exactly match the arguments to `.new`:
>       Post.stubs(:new).with({last_post_params: {foo: 'bar'}}).returns(fake_post)

Yeah..  I originally had tried your 2nd option...  Putting an expectation on
the arguments sent to new made no difference.  I just tried it again to verify,
and I still get the same error.  Seems so weird to me.

Patrick J. Collins

More information about the rspec-users mailing list