Project Ramon

A learning journey from a Ruby noob perspective

Rspec Part2: Test driving school

second_rspec_header_img

There are quite a few handy Rspec commands that can aid us. Today we’ll go over some of my favorite commands.

Rspec

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.
rsepc spec/models/user_spec.rb

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: rspec spec/models/user_spec.rb:11
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.

Advertisements

Categories: AirPair, Newbie, Ruby on rails

Tags: , , ,

1 reply

Trackbacks

  1. AirPair.com – What I’ve Learned pt. 2 | Project Ramon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s