[rspec-users] Stopping example execution?

Zach Dennis zach.dennis at gmail.com
Mon Jun 30 13:57:53 EDT 2008


On Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky <dchelimsky at gmail.com>
wrote:

> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote:
>
>> However, do you see where something like a return statement or end example
>> statement could be beneficial?
>> If you are working from the top down with your controller action
>> execution, then you only need to test your expectation
>> and then bail out of your action.  No need to further test or meet
>> requirements on anything else in that action because your
>> single test has been met.
>>
>> - in my example for making sure I find a user, I'd like to end execution
>> once I DID find the user, i shouldn't have to satisfy
>> requirements about finding an account and a person... I'll write those
>> expectations later in another nested describe group, as you
>> can see here, in a top down process
>>
>> PeopleController with a logged in user
>> - should find user
>>
>> PeopleController with a logged in user who has an account
>> - should find account
>>
>> PeopleController with a logged in user who doesnt have an account
>> - shouldn't find account
>> - should redirect ...
>>
>> PeopleController with a logged in user who has an account the person
>> belongs to
>> - should find person
>> - should assign person for the view
>>
>> PeopleController with a logged in user who has an account the requested
>> person does not belong to
>> - should not find person
>> - should ...
>>
>
> My instinct about this is that it would encourage long methods because it
> would make it less painful to test them, so I would be adverse to anything
> that let's you short circuit the method.
>
> Anybody else have opinions on that?


I'm just catching up on email now after being sick for the past six days,
but health aside my opinion is that I agree with David's opinion. Rather
than focusing on how-to write easier tests that complain less, start
focusing on how-to write the right tests that complain when necessary.

One of the benefits associated with feeling the pain of a test is that it
may be a sign to re-assess and refactor your code. This usually happens
early enough that it only takes a few minutes. Short circuiting essentially
gives you the ability to not feel the pain. Its like CIPA [0], but for code.
I would fear that the code would get so bad that by the time the test cried
with pain your code was already beyond easy repair and instead required
invasive surgery.

Tests are part of the nervous system of your application. When they hurt,
they're telling you something isn't right and that it should be addressed,

0 -
http://en.wikipedia.org/wiki/Congenital_insensitivity_to_pain_with_anhidrosis

-- 
Zach Dennis
http://www.continuousthinking.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080630/0ae5e849/attachment.html>


More information about the rspec-users mailing list