[rspec-users] How thorough do you test?
ben at benmabey.com
Wed Nov 21 13:38:29 EST 2007
I used to have the same thinking as you currently do. I found that my
view specs were brittle and offered false security. However, I actually
totally disagree with those statements now. The difference is how I have
been going about BDD. Before I would spec out my controllers then move
down to my models. I would then only test my views when some logic
mandated it. However, recently I have been letting my views drive my
entire development process (via the story runner as well, but that is
besides the point.) Starting from the view and working my way in has
made me really appreciate the place for view specing. Remember, BDD is
not just about "testing", but rather is a design process in and of
itself. The point of using mocks in the view is not all for speed
reasons.. by using mocks you can drive your entire design process from
the view. So, if you need to make a change to a model that would in end
effect the view you should really be changing the view spec first, have
it fail, make it pass, and move down to the model level. There was good
post about this outside-in approach the other day you might want to look at:
I hope this helps. I'm just learning myself. :)
Chris Olsen wrote:
> Testing models is great and would not be able to create anything without
> it, but I am finding testing the controllers and views is a pain.
> Rest based controllers don't seem to change that much when compared to
> the auto-generated code that obviously works.
> As for views I fail to see why testing it with a mock model does
> anything. Nothing is ensuring that when changes are made to the model
> that they will also be done to the mocks then causing the test to break.
> If anything, having the false security when all tests pass is worse, in
> that it may prevent you from double checking something crucial.
> I think tests for views makes sense when there is a condition that must
> be tested, ex. if a new member must fill in additional fields that are
> made visible only when they are from a certain country. A test may then
> make sense to ensure that the fields exist.
> I am still a noob, so if anyone can enlighten me I would appreciate it.
More information about the rspec-users