class RSpec::Matchers::BuiltIn::YieldWithArgs
Public Class Methods
new(*args)
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 184 def initialize(*args) @expected = args end
Public Instance Methods
description()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 203 def description desc = "yield with args" desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")" unless @expected.empty? desc end
failure_message_for_should()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 195 def failure_message_for_should "expected given block to yield with arguments, but #{positive_failure_reason}" end
failure_message_for_should_not()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 199 def failure_message_for_should_not "expected given block not to yield with arguments, but #{negative_failure_reason}" end
matches?(block)
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 188 def matches?(block) @probe = YieldProbe.probe(block) @actual = @probe.single_yield_args @probe.yielded_once?(:yield_with_args) && args_match? end
Also aliased as: ==
Private Instance Methods
all_args_match?()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 244 def all_args_match? return false if @expected.size != @actual.size @expected.zip(@actual).all? do |expected, actual| expected === actual || actual == expected end end
args_match?()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 229 def args_match? if @expected.empty? # expect {...}.to yield_with_args @positive_args_failure = "yielded with no arguments" if @actual.empty? return !@actual.empty? end unless match = all_args_match? @positive_args_failure = "yielded with unexpected arguments" + "\nexpected: #{@expected.inspect}" + "\n got: #{@actual.inspect} (compared using === and ==)" end match end
negative_failure_reason()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 219 def negative_failure_reason if all_args_match? "yielded with expected arguments" + "\nexpected not: #{@expected.inspect}" + "\n got: #{@actual.inspect} (compared using === and ==)" else "did" end end
positive_failure_reason()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 211 def positive_failure_reason if @probe.num_yields.zero? "did not yield" else @positive_args_failure end end