[rspec-users] Integrate or isolate views?

Sarah Allen sarah at ultrasaurus.com
Sun Jun 28 14:56:18 EDT 2009


I find that testing views independently is useful just to catch HTML  
errors that can sometime creep in during a re-factor.  These check  
important details that would be more tedious using cucumber.  The  
controller specs establish the post-condition for the controller  
independent of the view.  In the project I'm working on (which has  
mobile clients as well as a website), we have end-to-end integrations  
tests using cucumber that are primarily around our XML APIs (which are  
from my perspective, just a different kind of view) -- these also  
serve as developer docs.

My $.02

Sarah

On Jun 28, 2009, at 10:27 AM, Ben Mabey wrote:

>
> On Jun 28, 2009, at 8:32 AM, Jesse Crockett wrote:
>
>> Hello,
>>
>> I've been trying for two years to pick up BDD.  I'm making progress,
>> have just read through the chapters in The RSpec Book on spec'ing  
>> views
>> and controllers.
>>
>> What is the difference between using integrate_views and doing what
>> seems to be a lot of extra work to test the views in isolation?
>>
>> When I use integrate_views, can I write view spec in what would
>> otherwise be isolated controller spec?
>
> Correct, by default RSpec's controller specs will not render the  
> view.  This allows you to test the controller and view in complete  
> isolation.  By turning on integrate_views you can specify what the  
> rendered view should contain at the same time.  If you were to do  
> outside-in dev starting from the view you would start out by writing  
> an isolated view spec.  That spec would say that such and such would  
> be displayed.  This would in turn prompt you to assign something to  
> that view for it to be rendered.  That is then your signal that the  
> controller needs to assign that object.  So, you go up a level and  
> make sure that the controller action is assigning the needed object  
> for the view.  That object will most likely have to answer to some  
> methods used in the view so that prompts you to start writing  
> examples on the model level.  Isolation has it's benefits, however  
> an integration test (i.e. Cucumber scenario) is really needed to  
> make sure these parts are all working together as expected.
>
>>
>>
>> I read that I'm "encouraged" to do these in isolation, but IMHO the
>> chapter on spec'ing views is not very convincing in its own right, it
>> tells me that it's good, but doesn't show me as much, compared to the
>> examples and descriptions of circumstance that make several other
>> chapters very convincing.
>
> FWIW Jesse, you are not alone on this list in thinking that view  
> specs are not that valuable.  A lot of people share your opinion,  
> and I think Cucumber is generally used to specify the views the  
> majority of the time.  This enables you to specify your controllers  
> in isolation since your Cucumber features are cutting through the  
> entire stack.  I personally think  view specs are a very nice tool  
> to have available, but I would only use them on complex views.  By  
> complex I don't mean riddled with logic, but a view that has a lot  
> of stuff going on which is hard to set up all in one integration  
> test (or Cucumber scenario).  Since the majority of views are very  
> simple then verifying them just in Cucumber is good enough, IMO.
>
> -Ben
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

http://www.ultrasaurus.com





More information about the rspec-users mailing list