views:

5395

answers:

7
+9  A: 

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.

mislav
As I said, I'm not in rails so there's no controllers. But yes, "rake spec SPEC=file.rb" works. Thanks! I'm working on the Emacs integration now.
Jonathan Tran
Don't launch the rakefile if you can avoid it. It takes frickin ages
Orion Edwards
Just run the spec file directly! See Orion Edwards's answer.
James Baker
I changed the accepted answer, but the SPEC_OPTS param was helpful to me also.
Jonathan Tran
Now that's what I call a good answer. Why isn't it marked as "Answer"?
gmile
+11  A: 

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

spec 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.

Cameron Booth
+5  A: 

If you installed rspec as a plugin rather than as a gem, then you won't have the spec executable.

At any rate, All you need to do is run the file using ruby. The rspec code is clever enough to run the tests for you.

eg:

ruby myclass_spec.rb
Orion Edwards
+2  A: 

Alternatively, have a look at autotest.

Running autotest in a command window will mean that the spec file will be executed whenever you save it. Also, it will be run whenever the file you are speccing is run.

For instance, if you have a model spec file called person_spec.rb, and a model file that it is speccing called person.rb, then whenever you save either of these files from your editor, the spec file will be executed.

fatgeekuk
+3  A: 

specky.vim

Link to specky: http://www.vim.org/scripts/script.php?script_id=2286
jtimberman
+1  A: 

http://github.com/grosser/single%5Ftest lets you do stuff like..

rake spec:user          #run spec/model/user_spec.rb (searches for user*_spec.rb)
rake test:users_c       #run test/functional/users_controller_test.rb
rake spec:user:token    #run the first spec in user_spec.rb that matches /token/
rake test:user:token    #run all tests in user_test.rb that match /token/
rake test:last
rake spec:last
Zeke
A: 

from help (spec -h):

-l, --line LINE_NUMBER           Execute example group or example at given line.
                                 (does not work for dynamically generated examples)

Example: spec spec/runner_spec.rb -l 162

boblin