Module: RSpec::Mocks::MessageExpectation::ImplementationDetails

Included in:
RSpec::Mocks::MessageExpectation
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

Contains the parts of ‘MessageExpectation` that aren’t part of rspec-mocks’ public API. The class is very big and could really use some collaborators it delegates to for this stuff but for now this was the simplest way to split the public from private stuff to make it easier to publish the docs for the APIs we want published.

Other Constraints collapse

Other Constraints collapse

Instance Attribute Details

#argument_list_matcher=(value) ⇒ Object (writeonly)

Sets the attribute argument_list_matcher

Parameters:

  • value

    the value to set the attribute argument_list_matcher to.



413
414
415
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 413

def argument_list_matcher=(value)
  @argument_list_matcher = value
end

#error_generatorObject

Returns the value of attribute error_generator.



410
411
412
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 410

def error_generator
  @error_generator
end

#implementationObject

Returns the value of attribute implementation.



410
411
412
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 410

def implementation
  @implementation
end

#messageObject (readonly)

Returns the value of attribute message.



411
412
413
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 411

def message
  @message
end

#orig_objectObject (readonly)

Returns the value of attribute orig_object.



412
413
414
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 412

def orig_object
  @orig_object
end

#typeObject (readonly)



417
418
419
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 417

def type
  @type
end

Instance Method Details

#actual_received_count_matters?Boolean

Returns:

  • (Boolean)


588
589
590
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 588

def actual_received_count_matters?
  @at_least || @at_most || @exactly
end

#additional_expected_callsObject



575
576
577
578
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 575

def additional_expected_calls
  return 0 if @expectation_type == :stub || !@exactly
  @expected_received_count - 1
end

#advise(*args) ⇒ Object



532
533
534
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 532

def advise(*args)
  similar_messages << args
end

#and_yield_receiver_to_implementationObject



454
455
456
457
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 454

def and_yield_receiver_to_implementation
  @yield_receiver_to_implementation_block = true
  self
end

#called_max_times?Boolean

Returns:

  • (Boolean)


487
488
489
490
491
492
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 487

def called_max_times?
  @expected_received_count != :any &&
    !@at_least &&
    @expected_received_count > 0 &&
    @actual_received_count >= @expected_received_count
end

#description_for(verb) ⇒ Object



564
565
566
567
568
569
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 564

def description_for(verb)
  @error_generator.describe_expectation(
    verb, @message, @expected_received_count,
    @actual_received_count, expected_args
  )
end

#ensure_expected_ordering_received!Object



507
508
509
510
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 507

def ensure_expected_ordering_received!
  @order_group.verify_invocation_order(self) if @ordered
  true
end

#expectation_count_typeObject



558
559
560
561
562
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 558

def expectation_count_type
  return :at_least if @at_least
  return :at_most if @at_most
  nil
end

#expected_argsObject

rubocop:enable Metrics/ParameterLists



450
451
452
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 450

def expected_args
  @argument_list_matcher.expected_args
end

#expected_messages_received?Boolean

Returns:

  • (Boolean)


503
504
505
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 503

def expected_messages_received?
  ignoring_args? || matches_exact_count? || matches_at_least_count? || matches_at_most_count?
end

#generate_errorObject



540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 540

def generate_error
  if similar_messages.empty?
    @error_generator.raise_expectation_error(
      @message, @expected_received_count, @argument_list_matcher,
      @actual_received_count, expectation_count_type, expected_args,
      @expected_from, exception_source_id
    )
  else
    @error_generator.raise_similar_message_args_error(
      self, @similar_messages, @expected_from
    )
  end
end

#ignoring_args?Boolean

Returns:

  • (Boolean)


512
513
514
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 512

def ignoring_args?
  @expected_received_count == :any
end

#increase_actual_received_count!Object



592
593
594
595
596
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 592

def increase_actual_received_count!
  @actual_received_count_write_mutex.synchronize do
    @actual_received_count += 1
  end
end

#initialize(error_generator, expectation_ordering, expected_from, method_double, type = :expectation, opts = {}, &implementation_block) ⇒ Object

rubocop:disable Metrics/ParameterLists



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 420

def initialize(error_generator, expectation_ordering, expected_from, method_double,
               type=:expectation, opts={}, &implementation_block)
  @type = type
  @error_generator = error_generator
  @error_generator.opts = error_generator.opts.merge(opts)
  @expected_from = expected_from
  @method_double = method_double
  @orig_object = @method_double.object
  @message = @method_double.method_name
  @actual_received_count = 0
  @actual_received_count_write_mutex = Support::Mutex.new
  @expected_received_count = type == :expectation ? 1 : :any
  @argument_list_matcher = ArgumentListMatcher::MATCH_ALL
  @order_group = expectation_ordering
  @order_group.register(self) unless type == :stub
  @expectation_type = type
  @ordered = false
  @at_least = @at_most = @exactly = nil

  # Initialized to nil so that we don't allocate an array for every
  # mock or stub. See also comment in `and_yield`.
  @args_to_yield = nil
  @eval_context = nil
  @yield_receiver_to_implementation_block = false

  @implementation = Implementation.new
  self.inner_implementation_action = implementation_block
end

#invoke(parent_stub, *args, &block) ⇒ Object



473
474
475
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 473

def invoke(parent_stub, *args, &block)
  invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, &block)
end

#invoke_without_incrementing_received_count(parent_stub, *args, &block) ⇒ Object



478
479
480
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 478

def invoke_without_incrementing_received_count(parent_stub, *args, &block)
  invoke_incrementing_actual_calls_by(0, true, parent_stub, *args, &block)
end

#matches?(message, *args) ⇒ Boolean

Returns:

  • (Boolean)


463
464
465
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 463

def matches?(message, *args)
  @message == message && @argument_list_matcher.args_match?(*args)
end

#matches_at_least_count?Boolean

Returns:

  • (Boolean)


516
517
518
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 516

def matches_at_least_count?
  @at_least && @actual_received_count >= @expected_received_count
end

#matches_at_most_count?Boolean

Returns:

  • (Boolean)


520
521
522
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 520

def matches_at_most_count?
  @at_most && @actual_received_count <= @expected_received_count
end

#matches_exact_count?Boolean

Returns:

  • (Boolean)


524
525
526
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 524

def matches_exact_count?
  @expected_received_count == @actual_received_count
end

#matches_name_but_not_args(message, *args) ⇒ Object



494
495
496
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 494

def matches_name_but_not_args(message, *args)
  @message == message && !@argument_list_matcher.args_match?(*args)
end

#negative?Boolean

Returns:

  • (Boolean)


483
484
485
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 483

def negative?
  @expected_received_count == 0 && !@at_least
end

#negative_expectation_for?(message) ⇒ Boolean

Returns:

  • (Boolean)


584
585
586
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 584

def negative_expectation_for?(message)
  @message == message && negative?
end

#ordered?Boolean

Returns:

  • (Boolean)


580
581
582
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 580

def ordered?
  @ordered
end

#raise_out_of_order_errorObject



571
572
573
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 571

def raise_out_of_order_error
  @error_generator.raise_out_of_order_error @message
end

#raise_unexpected_message_args_error(args_for_multiple_calls) ⇒ Object



554
555
556
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 554

def raise_unexpected_message_args_error(args_for_multiple_calls)
  @error_generator.raise_unexpected_message_args_error(self, args_for_multiple_calls, exception_source_id)
end

#safe_invoke(parent_stub, *args, &block) ⇒ Object



468
469
470
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 468

def safe_invoke(parent_stub, *args, &block)
  invoke_incrementing_actual_calls_by(1, false, parent_stub, *args, &block)
end

#similar_messagesObject



528
529
530
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 528

def similar_messages
  @similar_messages ||= []
end

#unadvise(args) ⇒ Object



536
537
538
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 536

def unadvise(args)
  similar_messages.delete_if { |message| args.include?(message) }
end

#verify_messages_receivedObject



498
499
500
501
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 498

def verify_messages_received
  return if expected_messages_received?
  generate_error
end

#yield_receiver_to_implementation_block?Boolean

Returns:

  • (Boolean)


459
460
461
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_expectation.rb', line 459

def yield_receiver_to_implementation_block?
  @yield_receiver_to_implementation_block
end