Being Rspec noob, i dont know this question make sense. BUt i am really confused and couldnt get solution for this.
We have one new requirement, asked us to write Rspec test cases for existing project. They have application with rails3 that already working but they want rspec cases to be written now
My question is
Writing Rspec cases for existing application does make sense?
Can we write spec for already working project
Should we follow any guidelines to write specs for already written app
Thank you
As dpassage rightly pointed, your question has nothing to do with rspec. It’s about unit testing a legacy code.
Yes. It’s best when you write your tests first before you write the application. It’s never too late to write tests, starting late does not hurt.
Testing legacy code: Adding unit tests to legacy code
My two cents on this:
Add tests incrementally
Test first the most important parts of your application. i.e. Start writing the unit tests first and focus on important models (instead of all models). Once you test your models move to functional tests(controllers) and integration tests. Remember: To eat an elephant we need to eat one piece at a time.
If your existing models are difficult to write test, it implies that you need to refactor your code. Refactor to make your models simple to test.
Always write unit tests for new models/implementation from NOW.
Useful references: