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?
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 withtest
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").
You can use bash expansion. It isn't as powerful as a full regex but works most of the time. So you can do things like
rspec spec/models/user_*.spec
Docs here: https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html#Pattern-Matching
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With