[PATCH conductor 0/4 rev. 2] Provider Account API - show action

Richard Su rwsu at redhat.com
Wed Jul 25 23:56:30 UTC 2012


On 07/24/2012 02:37 AM, Petr Blaho wrote:
> On Monday, July 23, 2012 05:52:50 PM Richard Su wrote:
>> On 07/23/2012 07:10 AM, pblaho at redhat.com wrote:
>>> This is second revision of Provider Account API - show action.
>>>
>>> I added more tests for Credentials - based on FactoryGirl definitions
>>>
>> Hi Petr,
>>
>> Thanks for adding the tests for credentials. This looks better.
>>
>> After I had worked on the delete functionality. I noticed that the
>> provider account api rspec tests are a bit difficult to follow. And in
>> most cases are causing the test framework to do more work than is necessary.
>>
>> In general we want to setup mock objects at the beginning, create the
>> request, and assert the results have the expected values. The way you
>> constructed the tests caused the before blocks to be called multiple
>> times within the same test. You can see this by inserting a puts in one
>> of the index before blocks. You can also see more operations being
>> written out to $RAILS_ROOT/log/test.log than one would expect.
>>
>> I refactored them and attached the patch to this email. Let me know what
>> you think.
>>
>> - Richard
>
> Hi Richard,
>
> thank you for your input.
>
> Let me show you why I use rspec the way I use it.
>
> I believe in that one "it" block should have only one assert - "should" whenewer possible
> in order to spot failing test - red line - and instantly know what is wrong. The test is "talking" with me.
If there is an error the trace will tell you which line it failed on, so 
I don't think it is necessary to use multiple it blocks in that way.
>
> So when I use it blocks this way every before(:each) gets run before every "it" - of course.
>
> I am trying to use let blocks as much as possible - lazy evaluation and overriding ability are the reasons to use it.
>
> I will evaluate your patch for tests in terms of performance - there will be improvement over "1 should per it"
> but I think not in case of instance variables vs. let blocks (each before(:each) block gets called before each it block... )
> - and in that case it can be better to abandon my way of writing tests.
The penalty of using multiple it blocks can be high. On my vm, running

rspec spec/controllers/provider_accounts_controller.spec -e "API"

took 19.7 seconds. Applying my refactoring patch brought it down to 5.5 
seconds.

As for lets, it is probably a matter of personal perference. But I find 
the way I structured the before blocks and eliminating the lets to be 
easier to read and follow.
>
> Let me know what do you think.
>




More information about the aeolus-devel mailing list