【问题标题】:rspec pending results in falied testrspec 未决结果测试失败
【发布时间】:2014-07-30 16:21:09
【问题描述】:
it 'should be an array and not be empty' do
  pending
  expect(a.class).to be(Array)
  expect(a.empty?).to be(false)
  expect(a.first.class).to be(ExampleClass)
end

当我运行 rspec 时:

Failures:

  1) should be an array and not be empty FIXED
     Expected pending 'No reason given' to fail. No Error was raised.
     # ./spec/example_spec.rb:19

任何想法为什么这被列为失败?

【问题讨论】:

    标签: ruby-on-rails ruby rspec rspec3


    【解决方案1】:

    从 Rspec 3.x 开始,挂起的规范实际上是运行的,如果它们通过了,则认为它失败(因为如果通过了,那么 Rspec 认为它不应该处于挂起状态)。

    您可以使用skip 而不是pending 来确保您的规范实际上没有运行。

    更多信息:https://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#changes-to-pending-semantics-and-introduction-of-skip

    【讨论】:

      【解决方案2】:

      这是你的线索:

      should be an array and not be empty FIXED
      

      通过的事情将导致挂起的测试失败。查看文档中的示例 [1]、[2]。

      1. RSpec 2
      2. RSpec 3

      【讨论】:

        猜你喜欢
        • 2023-03-03
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多