[rspec-users] Mocking Models in Controller Specs...

Bart Zonneveld loop at superinfinite.com
Tue May 27 03:16:13 EDT 2008

On 26-mei-2008, at 21:52, Mark Dodwell wrote:

> I find myself doing this kind of thing a lot in Controller Specs:
>       @vacancy = mock_model(Vacancy)
>       @vacancy.stub!(:reference)
>       @vacancy.stub!(:title)
>       @vacancy.stub!(:created_at)
>       @vacancy.stub!(:updated_at)
>       @vacancy.stub!(:body)
>       @vacancy.stub!(:contract)
>       @vacancy.stub!(:location)
>       @vacancy.stub!(:salary)
>       @vacancy.stub!(:benefits)
>       @vacancy.stub!(:start_date)
>       @vacancy.stub!(:duration)
> I have to stub each of these methods so that the form renders  
> correctly
> (as I am using integrate_views). This just feels *way* too much  
> code and
> effort to do this. I have a spec for one controller (which just does
> plain old CRUD) that is over 300 LOC -- this seems a bit nuts to me  
> when
> the controller is only 50 LOC.

Or, consider moving code into the model, and test it there. See  


More information about the rspec-users mailing list