class RSpec::Matchers::BuiltIn::YieldWithArgs
@api private Provides the implementation for ‘yield_with_args`. Not intended to be instantiated directly.
Public Class Methods
new(*args)
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 200 def initialize(*args) @expected = args end
Public Instance Methods
description()
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 233 def description desc = 'yield with args' desc = "#{desc}(#{expected_arg_description})" unless @expected.empty? desc end
does_not_match?(block)
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 218 def does_not_match?(block) !matches?(block) && @probe.has_block? end
failure_message()
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 223 def failure_message "expected given block to yield with arguments, but #{positive_failure_reason}" end
failure_message_when_negated()
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 228 def failure_message_when_negated "expected given block not to yield with arguments, but #{negative_failure_reason}" end
matches?(block)
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 205 def matches?(block) @args_matched_when_yielded = true @probe = YieldProbe.new(block) do @actual = @probe.single_yield_args @actual_formatted = actual_formatted @args_matched_when_yielded &&= args_currently_match? end return false unless @probe.has_block? @probe.probe @probe.yielded_once?(:yield_with_args) && @args_matched_when_yielded end
supports_block_expectations?()
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 240 def supports_block_expectations? true end
supports_value_expectations?()
click to toggle source
@private
# File lib/rspec/matchers/built_in/yield.rb, line 245 def supports_value_expectations? false end
Private Instance Methods
all_args_match?()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 288 def all_args_match? values_match?(@expected, @actual) end
args_currently_match?()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 273 def args_currently_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: #{surface_descriptions_in(@expected).inspect}" \ "\n got: #{@actual_formatted}" end match end
expected_arg_description()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 257 def expected_arg_description @expected.map { |e| description_of e }.join(', ') end
negative_failure_reason()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 261 def negative_failure_reason if !@probe.has_block? 'was not a block' elsif @args_matched_when_yielded && !@expected.empty? 'yielded with expected arguments' \ "\nexpected not: #{surface_descriptions_in(@expected).inspect}" \ "\n got: #{@actual_formatted}" else 'did' end end
positive_failure_reason()
click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 251 def positive_failure_reason return 'was not a block' unless @probe.has_block? return 'did not yield' if @probe.num_yields.zero? @positive_args_failure end