How to run a single RSpec test? How to run a single RSpec test? ruby ruby

How to run a single RSpec test?


Usually I do:

rspec ./spec/controllers/groups_controller_spec.rb:42

Where 42 represents the line of the test I want to run.

EDIT1:

You could also use tags. See here.

EDIT 2:

Try:

bundle exec rspec ./spec/controllers/groups_controller_spec.rb:42


With Rake:

rake spec SPEC=path/to/spec.rb

(Credit goes to this answer. Go vote him up.)

EDIT (thanks to @cirosantilli): To run one specific scenario within the spec, you have to supply a regex pattern match that matches the description.

rake spec SPEC=path/to/spec.rb \          SPEC_OPTS="-e \"should be successful and return 3 items\""


You can pass a regex to the spec command which will only run it blocks matching the name you supply.

spec path/to/my_spec.rb -e "should be the correct answer"

2019 Update: Rspec2 switched from the 'spec' command to the 'rspec' command.