类: RSpec::Core::Example::Procsy

继承
Object
  • Object
显示全部
定义于
lib/rspec/core/example.rb

概述

注意

此类还公开 RSpec::Core::Example 的实例方法,通过代理传递给包装的 RSpec::Core::Example 实例。

包装了 ProcRSpec::Core::Example,用于在 around 钩子中使用。在 around 钩子中,我们需要传递这种特殊类型的对象(而不是原始的 RSpec::Core::Example),因为当存在多个 around 钩子时,我们必须递归地包装它们。

示例


RSpec.configure do |c|
  c.around do |ex| # Procsy which wraps the example
    if ex.[:key] == :some_value && some_global_condition
      raise "some message"
    end
    ex.run         # run delegates to ex.call.
  end
end

实例属性摘要 折叠

实例方法摘要 折叠

构造函数详细信息

#initialize(example, &block) ⇒Procsy

返回 Procsy 的新实例。

362
363
364
365
366
# File 'lib/rspec/core/example.rb', line 362
def initialize(example, &block)
  @example  = example
  @proc     = block
  @executed = false
end

实例属性详细信息

#examplevoid (只读)

The RSpec::Core::Example 实例。

333
334
335
# File 'lib/rspec/core/example.rb', line 333
def example
  @example
end

实例方法详细信息

#call(*args, &block) ⇒void 也称: run

调用 proc 并记录该示例已执行。

350
351
352
353
# File 'lib/rspec/core/example.rb', line 350
def call(*args, &block)
  @executed = true
  @proc.call(*args, &block)
end

#executed?Boolean

指示 around 钩子是否已执行该示例。

返回

  • (Boolean)
374
375
376
# File 'lib/rspec/core/example.rb', line 374
def executed?
  @executed
end

#to_procvoid

提供一个包装的 proc,该 proc 将在执行时更新我们的 executed? 状态。

358
359
360
# File 'lib/rspec/core/example.rb', line 358
def to_proc
  method(:call).to_proc
end