模块: RSpec::Core::Pending

包含于
ExampleGroup
定义于
lib/rspec/core/pending.rb

概述

提供标记示例为待处理的方法。这些方法可以在任何示例或钩子中调用。

定义在命名空间下

类: SkipDeclaredInExample

实例方法摘要 收起

实例方法详细信息

#pendingvoid #pending(message) ⇒ void

注意

当在示例主体中使用 pending 时,使用此方法的钩子(如 before(:example))已运行。这意味着 before 钩子中的代码失败将阻止示例被视为待处理,因为示例主体不会被执行。如果您需要将钩子也视为待处理,可以使用待处理元数据作为替代方法,例如 it "does something", pending: "message"

将示例标记为待处理。示例的其余部分将继续执行,如果它通过,则示例将失败,表明可以删除待处理项。

示例

describe "some behaviour" do
  # reported as "Pending: no reason given"
  it "is pending with no message" do
    pending
    raise "broken"
  end
  # reported as "Pending: something else getting finished"
  it "is pending with a custom message" do
    pending("something else getting finished")
    raise "broken"
  end
end

参数

  • message (String) (默认为: nil)

    添加到摘要报告中的可选消息。

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rspec/core/pending.rb', line 62
def pending(message=nil, &_block)
  current_example = RSpec.current_example
  if block_given?
    raise ArgumentError, <<-EOS.gsub(/^\s+\|/, '')
      |The semantics of `RSpec::Core::Pending#pending` have changed in
      |RSpec 3. In RSpec 2.x, it caused the example to be skipped. In
      |RSpec 3, the rest of the example is still run but is expected to
      |fail, and will be marked as a failure (rather than as pending) if
      |the example passes.
      |
      |Passing a block within an example is now deprecated. Marking the
      |example as pending provides the same behavior in RSpec 3 which was
      |provided only by the block in RSpec 2.x.
      |
      |Move the code in the block provided to `pending` into the rest of
      |the example body.
      |
      |Called from #{CallerFilter.first_non_rspec_line}.
      |
    EOS
  elsif current_example
    Pending.mark_pending! current_example, message
  else
    raise "`pending` may not be used outside of examples, such as in " \
          "before(:context). Maybe you want `skip`?"
  end
end

#skipvoid #skip(message) ⇒ void

将示例标记为待处理并跳过执行。

示例

describe "an example" do
  # reported as "Pending: no reason given"
  it "is skipped with no message" do
    skip
  end
  # reported as "Pending: something else getting finished"
  it "is skipped with a custom message" do
    skip "something else getting finished"
  end
end

参数

  • message (String) (默认为: nil)

    添加到摘要报告中的可选消息。

引发

110
111
112
113
114
115
116
# File 'lib/rspec/core/pending.rb', line 110
def skip(message=nil)
  current_example = RSpec.current_example
  Pending.mark_skipped!(current_example, message) if current_example
  raise SkipDeclaredInExample.new(message)
end