Besides hacking the internal components of RSpec, which is probably not a good idea, the only way to do this is to abuse the available option:
The tag parameter is a good candidate for this, since it allows you to enter key / value pairs. The advantage of this is that it can be installed in a .rspec file and can be overridden by a command line argument. For instance,
.rspec configuration
--format documentation --color --tag timeout:10 --require spec_helper
command line
rspec --tag timeout:2
You just need to be careful and make sure that you remove the tag from the filter or all tests are filtered out ... To use this, in your case, you simply do:
RSpec.configure do | config | timeout = config.filter.delete(:timeout) || 10 config.around do |example| begin Timeout.timeout(timeout) { example.run } rescue Timeout::Error skip "Timed out after #{timeout} seconds" end end end
In this particular example, setting the timeout to zero will disable the use of timeouts.
The order of priority from highest to lowest is command line arg > .rspec configuration > default specified in your config block .
David source share