I have been immersed in production codebases for my Fohr Card and Fractured Atlas projects. At first, it feel initimidating trying to figure out all of the models and related associations. I have found that a great way to wrap your head around the code base is to create a new branch and test the code.
A good basic set-up is to start unit testing the models. In order to do this depends on if your codebase is using a relational database or something like Mongoid.
Relational Databases
1 2 3 4 5 6 7 8 9 10 11 |
|
- Guard RSpec waits for you to save your files and automatically runs your tests, thereby reducing the time needed to run tests.
- I like the RSpec syntax over Unit Test and Mini Test.
- Factory Girl Rails creates objects for your tests. This gem deserves its own blog post.
- The Faker Gem is used in conjunction with Factory Girl Rails to create fake data.
- I like to use Shoulda Matchers to test validaitons and associations in the code. This gem and firing up Rails Console to play with the objects in my testing is the crux to learning a new codebase.
- Some people find Terminal Notifier annoying, but it helps me know if my tests pass when I have Sublime maximized on my 11 inch MacBook Air screen.
Mongoid
1 2 3 4 5 6 7 8 9 10 11 |
|
The gems for Mongoid testing are similar to those used in testing with a relational database.
- The Fabrication gem is similar to building objects with Factory Girl, except the documentation website rocks.
- The Mongoid RSpec gem is similar to Shoulda-Matchers
Gems
Guard RSpec RSpec Rails Factory Girl Rails Faker Shoulda Matchers Terminal Notifier Guard Fabrication Mongoid RSpecOther Resources
I found this book invaluable in learning best practices in testing: Everday RSpech/t Victoria Friedman