RSpec:如何在所有其他规范之后运行功能规范



我们有一个相当复杂的水豚和铬的集成规范设置。这会导致功能规格变慢。

如果在所有其他规范之后执行功能规范,那就太好了。因为集成测试需要相当长的时间才能"启动"并找到一个错误,而以前一个简单的请求或单元测试会更快地找到这个错误。

问题:如何确保 rspec 紧跟在其他规范之后运行功能规范,但在不破坏 simplecov 的情况下将它们随机排序为种子?

RSpec 允许设置自定义排序。在spec_helper.rb中输入后,将导致 rspec 在功能规范之前运行所有其他测试,并按种子随机排序,而不会破坏 simplecov:

# Setup custom ordering to ensure that feature tests are executed after all other tests.
# Within this partition the tests are seed based randomly ordered.
config.register_ordering(:global) do |items|
  features, others = items.partition { |e| e.metadata[:type] == :feature }
  random_ordering = RSpec::Core::Ordering::Random.new(config)
  random_ordering.order(others) + random_ordering.order(features)
end

请确保在 rspec 调用或.rspec文件中没有--order random

最新更新