Logo: Relish

  1. Sign up
  2. Sign in

Project: RSpec Core 3.0

pattern

Use the --pattern option to tell RSpec to look for specs in files that match
a pattern other than "**/*_spec.rb".

Background
Given
a file named "spec/example_spec.rb" with:
RSpec.describe "two specs here" do
  it "passes" do
  end

  it "passes too" do
  end
end
And
a file named "spec/example_test.rb" with:
RSpec.describe "only one spec" do
  it "passes" do
  end
end
Scenarios
By default, RSpec runs files that match `"**/*_spec.rb"`
When
I run rspec
Then
the output should contain "2 examples, 0 failures"
The `--pattern` flag makes RSpec run files matching the specified pattern and ignore the default pattern
When
I run rspec -P "**/*_test.rb"
Then
the output should contain "1 example, 0 failures"
The `--pattern` flag can be used to pass in multiple patterns, separated by comma
When
I run rspec -P "**/*_test.rb,**/*_spec.rb"
Then
the output should contain "3 examples, 0 failures"
The `--pattern` flag accepts shell style glob unions
When
I run rspec -P "**/*_{test,spec}.rb"
Then
the output should contain "3 examples, 0 failures"

Last published over 2 years ago by myronmarston.