Discover your missing specs

Posted by Curtis Miller Curtis Miller

Have you ever had the feeling that something was missing, but you weren't quite sure what it was? I was looking at my code coverage the other day and thought to myself that it seemed like I was missing something. Rather than go through each file manually to see if it had an associated spec, I created a small rake task that does this for you.

The rake task looks at all the files in your app directory and tries to find an associated file in the spec directory. It follows the current Rspec generator naming conventions and if it doesn't find the associated file it runs the generator to create it. It assumes that your app directory and spec directory follow the same directory structure and that you should at least have one test file for every application file.

You may find this as part of the Rake Tasks plugin.

To install:

script/plugin install http://svn.integrumtech.com/public/plugins/rake_tasks/

OR

piston import http://svn.integrumtech.com/public/plugins/rake_tasks/ vendro/plugins/rake_tasks

(Piston is one of my new favorite tools)

My additions are two rake tasks:

rake spec:check     # Check files in the app directory for corresponding test files in the spec directory.
rake spec:sync      # Check for missing test files in the spec directory and create them if they don't exist.

If you're using Subversion, then you can also use the Subversion tasks that come with the Rake Tasks plugin to add the new spec files to your repository:

rake svn:add        # Adds new files to subversion
rake svn:remove     # Removes missing files from subversion
rake svn:ignore     # Configures svn:ignore properties on log, tmp, db/schema.rb and config/database.yml
rake svn:conflicts  # Resolves all svn conflicts by keeping the working file

This plugin was also the original home of some tasks that you may already be familiar with (I use them all the time):

rake db:create      # Creates the databases defined in your config/database.yml (unless they already exist)
rake db:drop        # Drops the database for your currenet RAILS_ENV as defined in config/database.yml
rake db:reset       # Drops, creates and then migrates the database for your current RAILS_ENV

Those three were merged into Rails edge in May of this year.

Thanks to Josh Knowles, Derek Neighbors, and Josh Huckabee for their feedback on the addition. If you have any comments, bugs, patches, questions, etc. please send them my way.



Velocity Labs

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Hire us!