akshatpradhan/spoutlets — pull request #31 by priyaaank (2013-02-22 05:21:40+00:00)
Title: Pull request to write an entry spec and to define factories correctly

Hey Akshat,

I have done following things in this pull request.
* Added very simple spec for Entry. Key thing to note is that entry doesn't have any behavior to it right now. So essentially only thing you can test is whether the declarations of attributes is intact or not. There is a concise way to test that and I have added it.
* Your factories are loaded automagically if you define them in factories folder under specs. And this is the case in your scenario as well. Factory.find_definitions is suppose to load the definitions, which you don't need to do in console. So when you do rails console, all you need to do is FactoryGirl.create(:entry) and that definition is already available to you.
* I have assumed some behavior for your specs and added a simple spec for anxiety and happiness level. there are two ways to execute the before block. If you check in first I have used "let" and second I have used "before" block. Let defines a dynamic method "entry" which has a body as defined in block, however it is not executed unless a test in that context calls for it. On the other hand before is executed before each test scenario irrespective of whether the declared instance variables are used in scenarios or not. I personally like the first approach to keep tests lean and performant. However in some cases when you need to make multiple initializations and declarations, you would have to do a before block. Remember, test only one thing in a single scenario.

I have also taken the liberty to show an indicative way to define your factories, take a look and let me know if you have any questions. I am willing to talk in depth about some of these.