【问题标题】:Why RSpec runs examples in the order not as they're declared?为什么 RSpec 不是按照声明的顺序运行示例?
【发布时间】:2014-10-30 12:39:59
【问题描述】:

我使用的是 RSpec 2.99,并且有以下简单的规范文件:

describe 'thing' do

  context 'context' do
    it 'one thing' do
      # ...
    end

    it 'another thing' do
      # ...
    end
  end

  it 'without context' do
    # ...
  end

end

输出是:

$ bundle exec rspec test_spec.rb -fd

thing
  without context
  context
    one thing
    another thing

Finished in 0.00092 seconds
3 examples, 0 failures

我不明白为什么without context 会在之前 context

这与--order 的文档中所写的内容相矛盾:

[...] 按照定义的顺序执行组和示例 [...]

我在这里错过了什么?

更新:在同一个文档页面上有一个概念:

嵌套组始终从顶层运行到底层 [...]

这是否适用于给定的情况?如果是这样,事实证明我无法让 RSpec 在规范文件中精确运行示例(抛开我为什么需要它的问题)。

【问题讨论】:

  • 与 RSpec 3 相同,文档似乎有误。
  • 您的更新仅适用于rand 订单。
  • 也许,不是完全错误,而是不够清楚。
  • 我认为你应该file a bug report
  • 你已经做到了! :-)

标签: ruby rspec


【解决方案1】:

文档不准确。当一个示例组运行时,它首先是runs its examples,然后是recursively delegates to each of its child example groups。这意味着组的示例将始终在其嵌套示例组之前运行,即使首先定义了某些嵌套组。

但是,使用--order defined,每个类别中的项目将按定义的顺序运行。

这是我们在编写文档时(甚至在命名--order defined 选项时)没有考虑到的一个微妙之处。

至于我们应该怎么做...我将在the issue you opened 上提出一些想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2016-12-15
    • 1970-01-01
    相关资源
    最近更新 更多