【问题标题】:RSpec: How to run the feature specs after all other specsRSpec:如何在所有其他规范之后运行功能规范
【发布时间】:2018-03-15 15:23:12
【问题描述】:

我们使用 capybara 和 chrome 进行了相当复杂的集成规范设置。这会导致缓慢的功能规范。

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

问题:如何确保 rspec 在其他规范之后立即运行功能规范,但随机排序它们作为种子而不破坏 simplecov?

【问题讨论】:

  • 一问一答?
  • 是的,当您打开一个 SO 问题时,您可以激活“回答您自己的问题”复选框并提供问题的答案权:) 请参阅 stackoverflow.blog/2011/07/01/…

标签: ruby ruby-on-rails-3 rspec capybara


【解决方案1】:

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

【讨论】:

  • 你当然可以这样做。但是,当您关闭随机排序时,您可能会隐藏某些与订单相关的错误。
  • 随机排序实际上并没有关闭。这些示例仍然是随机排序的,但是集成测试在其他测试之后运行。使用数据库清理器和 capybara 应该不会出现任何与订单相关的错误,因为 capybara 会生成自己的服务器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-20
相关资源
最近更新 更多