class RSpec::Matchers::BuiltIn::YieldSuccessiveArgs

@api private Provides the implementation for `yield_successive_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 282
def initialize(*args)
  @expected = args
end

Public Instance Methods

description() click to toggle source

@private

# File lib/rspec/matchers/built_in/yield.rb, line 322
def description
  "yield successive args(#{expected_arg_description})"
end
does_not_match?(block) click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 305
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 310
def failure_message
  'expected given block to yield successively 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 316
def failure_message_when_negated
  'expected given block not to yield successively with arguments, ' \
  "but #{negative_failure_reason}"
end
matches?(block) click to toggle source

@private

# File lib/rspec/matchers/built_in/yield.rb, line 287
def matches?(block)
  @actual_formatted = []
  @actual = []
  args_matched_when_yielded = true
  yield_count = 0

  @probe = YieldProbe.probe(block) do |*arg_array|
    arg_or_args = arg_array.size == 1 ? arg_array.first : arg_array
    @actual_formatted << RSpec::Support::ObjectFormatter.format(arg_or_args)
    @actual << arg_or_args
    args_matched_when_yielded &&= values_match?(@expected[yield_count], arg_or_args)
    yield_count += 1
  end

  return false unless @probe.has_block?
  args_matched_when_yielded && yield_count == @expected.length
end
supports_block_expectations?() click to toggle source

@private

# File lib/rspec/matchers/built_in/yield.rb, line 327
def supports_block_expectations?
  true
end

Private Instance Methods

expected_arg_description() click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 333
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 345
def negative_failure_reason
  return 'was not a block' unless @probe.has_block?

  'yielded with expected arguments' \
  "\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
  "\n         got: [#{@actual_formatted.join(", ")}]"
end
positive_failure_reason() click to toggle source
# File lib/rspec/matchers/built_in/yield.rb, line 337
def positive_failure_reason
  return 'was not a block' unless @probe.has_block?

  'yielded with unexpected arguments' \
  "\nexpected: #{surface_descriptions_in(@expected).inspect}" \
  "\n     got: [#{@actual_formatted.join(", ")}]"
end