There are quite a few handy Rspec commands that can aid us. Today we’ll go over some of my favorite commands.
It makes sense to start with the
rspec command. This runs all specs in all files that you have created. I have an article_spec, an image_spec, a user_spec and video_spec files.
These are all model spec files, there are also abilities within our Rspec spec folder to add controllers, helpers, and views.
To run a specific spec_file, you can type the command
rspec followed by the path to the file you want ran.
John Davison shared a nifty tip to specify only one spec to be ran by appending a
:11 to the end of our rspec test command.
So the complete command could look something like:
In Rspec version 2.14 you could also do
rspec spec/models/user_spec.rb --line_number 11,
but I find John’s tip to be easier to remember.
And finally, to finish off my small collection of Rspec commands deals with rake. To list all Rspec rake tasks you can type the command
rake -T spec.