RSpec:如何 运行 在所有其他规格之后的功能规格
RSpec: How to run the feature specs after all other specs
我们对水豚和 chrome 进行了相当复杂的集成规范设置。这会导致功能规格变慢。
如果功能规范在所有其他规范之后执行,那就太好了。因为集成测试需要相当长的时间 "boot" 并找到一个简单的请求或单元测试以前可以更快找到的错误。
问题:如何确保 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
我们对水豚和 chrome 进行了相当复杂的集成规范设置。这会导致功能规格变慢。
如果功能规范在所有其他规范之后执行,那就太好了。因为集成测试需要相当长的时间 "boot" 并找到一个简单的请求或单元测试以前可以更快找到的错误。
问题:如何确保 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