123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::AndYieldImplementation Private

Relationships & Source Files
Inherits: Object
Defined in: rspec-mocks/lib/rspec/mocks/message_expectation.rb

Overview

Handles the implementation of an and_yield declaration.

Other Constraints

Constructor Details

.new(args_to_yield, eval_context, error_generator) ⇒ AndYieldImplementation

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/message_expectation.rb', line 695

def initialize(args_to_yield, eval_context, error_generator)
  @args_to_yield = args_to_yield
  @eval_context = eval_context
  @error_generator = error_generator
end

Instance Method Details

#call(*_args_to_ignore, &block)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/message_expectation.rb', line 701

def call(*_args_to_ignore, &block)
  return if @args_to_yield.empty? && @eval_context.nil?

  @error_generator.raise_missing_block_error @args_to_yield unless block
  value = nil
  block_signature = Support::BlockSignature.new(block)

  @args_to_yield.each do |args|
    unless Support::StrictSignatureVerifier.new(block_signature, args).valid?
      @error_generator.raise_wrong_arity_error(args, block_signature)
    end

    value = @eval_context ? @eval_context.instance_exec(*args, &block) : yield(*args)
  end
  value
end