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

时间:2019-09-21 00:53:34

标签: ruby rspec

给出以下测试文件

require 'rails_helper'

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

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

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

此致

1 个答案:

答案 0 :(得分:3)

使用filtering,我可以运行其他测试,然后每个测试都使用上下文type: :service描述块。

例如

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