[rspec-users] Mocking Models in Controller Specs...
Mark Dodwell
lists at ruby-forum.com
Mon May 26 15:52:43 EDT 2008
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.
Does anybody have any suggestions on how to avoid this or perhaps I am
doing something wrong!?
I make use of a Factory pattern to create instances for my model unit
tests -- could I use a similar pattern for a 'mock factory'? Is anybody
doing anything similar?
~ Mark
--
Posted via http://www.ruby-forum.com/.
More information about the rspec-users
mailing list