类: RSpec::Matchers::BuiltIn::Compound::NestedEvaluator 私有

继承
Object
  • Object
显示全部
定义在
lib/rspec/matchers/built_in/compound.rb

概述

此类是私有 API 的一部分。 应尽量避免使用此类,因为它可能在未来被移除或更改。

通常,我们会按顺序评估匹配。对于类似 expect(x).to foo.and bar 的表达式,它会变成

expect(x).to foo expect(x).to bar

对于块期望,我们需要嵌套它们,以便 expect { x }.to foo.and bar 变成

expect { expect { x }.to foo }.to bar

这是必要的,以便 expect 块只执行一次。

实例方法摘要 折叠

构造函数详情

#initialize(actual, matcher_1, matcher_2) ⇒NestedEvaluator

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能在未来被移除或更改。

返回一个新的 NestedEvaluator 实例。

157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rspec/matchers/built_in/compound.rb', line 157
def initialize(actual, matcher_1, matcher_2)
  @actual        = actual
  @matcher_1     = matcher_1
  @matcher_2     = matcher_2
  @match_results = {}
  inner, outer = order_block_matchers
  @match_results[outer] = outer.matches?(Proc.new do |*args|
    @match_results[inner] = inner.matches?(inner_matcher_block(args))
  end)
end

实例方法详情

#matcher_matches?(matcher) ⇒Boolean

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能在未来被移除或更改。

返回

  • (Boolean)
170
171
172
173
174
175
176
177
# File 'lib/rspec/matchers/built_in/compound.rb', line 170
def matcher_matches?(matcher)
  @match_results.fetch(matcher) do
    raise ArgumentError, "Your #{matcher.description} has no match " \
     "results, this can occur when an unexpected call stack or " \
     "local jump occurs. Perhaps one of your matchers needs to " \
     "declare `expects_call_stack_jump?` as `true`?"
  end
end