使用--exclude_pattern 选项

使用--exclude-pattern 选项告诉 RSpec 跳过查找与指定模式匹配的文件中的规范。

背景

给定一个名为“spec/models/model_spec.rb”的文件,其中包含

RSpec.describe "two specs here" do
  it "passes" do
  end

  it "passes too" do
  end
end

以及一个名为“spec/features/feature_spec.rb”的文件,其中包含

RSpec.describe "only one spec" do
  it "passes" do
  end
end

默认情况下,RSpec 运行与"**/*_spec.rb" 匹配的文件

我运行rspec

那么输出应该包含“3 个示例,0 个失败”。

--exclude-pattern 标志使 RSpec 跳过匹配的文件

我运行rspec --exclude-pattern "**/models/*_spec.rb"

那么输出应该包含“1 个示例,0 个失败”。

--exclude-pattern 标志可用于传递多个模式,以逗号分隔

我运行rspec --exclude-pattern "**/models/*_spec.rb, **/features/*_spec.rb"

那么输出应该包含“0 个示例,0 个失败”。

--exclude-pattern 标志接受 shell 风格的 glob 联合

我运行rspec --exclude-pattern "**/{models,features}/*_spec.rb"

那么输出应该包含“0 个示例,0 个失败”。

--exclude-pattern 标志可与--pattern 标志一起使用

我运行rspec --pattern "spec/**/*_spec.rb" --exclude-pattern "spec/models/*_spec.rb"

那么输出应该包含“1 个示例,0 个失败”。