On Monday, July 23, 2012 05:52:50 PM Richard Su wrote:
On 07/23/2012 07:10 AM, pblaho@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.
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.
Let me know what do you think.