Class: RSpec::Mocks::AndYieldImplementation

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb

Overview

Handles the implementation of an ‘and_yield` declaration.

Other Constraints collapse

Constructor Details

#initialize(args_to_yield, eval_context, error_generator) ⇒ AndYieldImplementation

Returns a new instance of AndYieldImplementation.



695
696
697
698
699
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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) ⇒ Object



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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