Is It Possible To Pass A regex to the 'rspec` Command line command?

regex, rspec, ruby, ruby-on-rails, ruby-on-rails-4

Solution

You can use for examples :-

It will load for you all files, whose names start with `test`

rspec -P spec/**/test*_spec.rb
rspec -P spec/**/test*.rb

It will load for you all files, which has a word `test` in middle, but not start with `test`

rspec -P spec/**/*?test*_spec.rb

It will run all files whose name start with test. Like test_1_spec.rb, test_2_spec.rb etc. But you have to run this command from your project root directory.

Docs for -P / --pattern flag

Information can also be obtained from `--help`

arup$ rspec -help | grep PATTERN
 -P, --pattern PATTERN  Load files matching pattern (default: "spec/**/*_spec.rb").

Problem

When calling `rspec` from the command line, I know that you can use the `-e` or `-example` flag to pass in a regex which it matched against the content of any `it` blocks, but is there a way to pass in a regex and have RSpec run files whose names match that regex?

Original source