[rspec-users] [newbie] tradeoffs of direct model access vs. simulated browser (webrat)

George Dinwiddie lists at iDIAcomputing.com
Thu Aug 5 11:03:49 EDT 2010

Matt, Lille,

On 8/4/10 2:58 PM, Matt Wynne wrote:
> On 4 Aug 2010, at 18:44, Lille wrote:
>> Hi,
>> My app involves the elicitation of tabular data over a succession of
>> controller/model/view groups. The net result is a numeric outcome
>> based on the entered data (basically, it's a spreadsheet on Rails.)
>> Here is the nub of my question about developing such a thing with
>> RSpec:
>> + if I test with a simulated browser approach, my scenarios will need
>> span multiple controller/model/view triads to confirm the expected
>> result in as many cases as I feel I need to cover. Basically, an
>> entire app use-cycle is contained in every scenario -- this doesn't
>> remind me of anything I've seen in "The RSpec Book", for example.
>> + I think I prefer rspec'ing the models directly -- it's concise and I
>> don't duplicate simulated browser actions for no particular reason.
>> What's the point of confirming that different data in the same set of
>> fields is submitted successfully, like 20 times? I'll only simulate
>> the browser to build the view/controllers and test their behavior when
>> inputs are inadequate or require differential responses.
>> My preferred strategy is sort of like saying to the client: 1) here
>> are all the numeric outcomes we need to confirm, and 2) here in a
>> smaller, overlapping set are the behavioral outcomes we need to
>> confirm
>> In short, it seems to me the simulated browser approach (webrat) is
>> overkill when one is dealing with exhaustive cases and there is no
>> differential response in the controller or view parts based on them.
>> Lille
> If your goal is to have a set of executable specs that the client can
> validate by reading them, consider writing them in Cucumber but
> wiring them directly to the models.

Yes, I'm a big proponent of verifying business rules at the lowest level 
possible.  It's easier to do so, and it also helps cover all the 

> George Dinwiddie has blogged about this I think but I can't find the
> reference.

I've certainly talked a lot on acceptance testing at multiple levels, 
but I don't think I've blogged on it, yet.  I should remedy that.

> You can combine these with some other scenarios that focus on the
> behaviour of the user interface if you feel you need that assurance.

Yes, you'll probably always need at least one scenario to verify that 
things are wired up correctly.

  - George

   * George Dinwiddie *                      http://blog.gdinwiddie.com
   Software Development                    http://www.idiacomputing.com
   Consultant and Coach                    http://www.agilemaryland.org

More information about the rspec-users mailing list