How do you run a single test/spec file in RSpec? How do you run a single test/spec file in RSpec? ruby ruby

How do you run a single test/spec file in RSpec?


Or you can skip rake and use the 'rspec' command:

rspec path/to/spec/file.rb

In your case I think as long as your ./spec/db_spec.rb file includes the appropriate helpers, it should work fine.

If you're using an older version of rspec it is:

spec path/to/spec/file.rb


The raw invocation:

rake spec SPEC=spec/controllers/sessions_controller_spec.rb \          SPEC_OPTS="-e \"should log in with cookie\""

Now figure out how to embed this into your editor.


This question is an old one, but it shows up at the top of Google when searching for how to run a single test. I don't know if it's a recent addition, but to run a single test out of a spec you can do the following:

rspec path/to/spec:<line number>

where -line number- is a line number that contains part of your test. For example, if you had a spec like:

1: 2: it "should be awesome" do3:   foo = 34:   foo.should eq(3)5: end6:

Let's say it's saved in spec/models/foo_spec.rb. Then you would run:

rspec spec/models/foo_spec.rb:2

and it would just run that one spec. In fact, that number could be anything from 2 to 5.

Hope this helps!