Topic: Running only certain tests based on a flag

I want to be able the have test_all and test_long which run different tests. Or even different lines with in the tests. I have found some great things to test but they take a few seconds per each call. So when doing my testing during development I don't want to run these as they slow me down. I want to run these longer lines only sometimes (like right after code is checked into svn).

def test_something

#quick stuff
assert true
....
...

if(conditional_flag_is_set)
  assert slow command
end

end

I don't know where I can set the conditional_flag I thought perhaps while calling the tests with rake as an option, or setting it in the config/enviroment/test.rb, but so far haven't come up with a nice clean solution.

I am sure someone has done this before so I would love any help from someone with more experience in ruby testing.

thanks,
Dan

Re: Running only certain tests based on a flag

I think you can pass environment variables through a rake task like this:

rake test FOO=bar

Then fetch the passed value with ENV['foo']. Untested.

You may want to consider doing this in a separate rake task. I can imagine you could add a rake task that does this:

rake test:long

Which would change a variable/constant. Not exactly sure how to do that though.

Railscasts - Free Ruby on Rails Screencasts