如何根据 RSpec 中的测试类型执行测试

How to perform tests based on the type of test in RSpec

给定以下测试文件

require 'rails_helper'

RSpec.describe PurchaseCarService, type: :service do
  #...
end

如何对 :service 类型的所有规范执行通用测试?

我打算让所有(例如)服务对象执行通用服务标准。

此致,

使用 filtering 我能够 运行 在每个描述块与上下文 type: :service 之前进行额外的测试。

例如

RSpec.configure do |c|
  c.before(:example, type: :service) do
    # Run some common tests
  end
end