Class: RSpec::Mocks::AndYieldImplementation

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/message_expectation.rb

Overview

Handles the implementation of an `and_yield` declaration.

Instance Method Summary (collapse)

Constructor Details

- (AndYieldImplementation) initialize(args_to_yield, eval_context, error_generator)

Returns a new instance of AndYieldImplementation



533
534
535
536
537
# File 'lib/rspec/mocks/message_expectation.rb', line 533

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

- (Object) call(*args_to_ignore, &block)



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/rspec/mocks/message_expectation.rb', line 539

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::MethodSignatureVerifier.new(block_signature, args).valid?
      @error_generator.raise_wrong_arity_error(args, block_signature)
    end

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