[rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec

Nathan Sutton nathan.sutton at gmail.com
Sun Jul 29 02:36:46 EDT 2007

One of the things that turned me on to BDD and RSpec was speccing  
views first, that the desired end would drive the development.  In  
previous projects while using Test::Unit I would try to make educated  
guesses as to what would be needed in the model and controllers to  
derive the view without actually writing the view until afterwards.  
This is all because testing relied on each previous layer working for  
the next to work, first models, then controllers, then views.  And  
while for the most part the educated guesses panned out, and I'd do  
the models/controllers/views incrementally, I'd repeat a specific  
process a lot.

Test/write model(s)
Test/write controller(s)
Test/write view(s)...oops, I forgot something or I need some extra  
functionality out of the model (or controller) which I didn't guess  
the view would need.

Lets go back to the model to test/add the functionality
Lets test/add functionality in the controller to include this
Lets test the functionality in the view that we had to go back and  
write support code for (if you even do this with Test::Unit, flooding  
your functional tests with ugly ugly ugly tests)

Rinse and repeat, quickly trying to switch contexts from models to  
controllers to views.  While testing helps you predict failures when  
making changes, it's not perfect, and predicting problems in the  
views is even more difficult with the current state of view testing  
in Test::Unit.

While it is still rather agile, and changing the contexts isn't  
really much of a switch in this case, I think a lot could be avoided  
by doing views first and letting it drive the controllers and  
models.  Then the cycle of incremental additions is to add features  
instead of adding things you forgot.  Adding value, rather than  
recovering intended functionality that wasn't foreseen to be needed  
in your views.

Maybe it's all in my head, but I enjoy adding new functionality more  
than spending time going back and adding backend functionality that  
wasn't foreseen to be needed by the frontend.

So what am I on about?  Well, I'm having trouble doing just that.  I  
want to do View-Driven-Development by Behavior-Driven-Development,  
but I'm stumped really where to begin.  Ideally I'd like to see a  
tutorial or something that walks though it, or browse through some  
projects using RSpec for the views, but I can't seem to find any.   
Maybe I'm not looking hard enough or I don't know where to look.

Could anyone help me with this?

Nathan "fowlduck" Sutton

P.S. Excerpt from my crappy blog, if it matters, http:// 

More information about the rspec-users mailing list