class RSpec::Mocks::AnyInstance::MessageChains

@private

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/rspec/mocks/any_instance/message_chains.rb, line 6
def initialize
  super {|h,k| h[k] = []}
end

Public Instance Methods

add(method_name, chain) click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 11
def add(method_name, chain)
  self[method_name] << chain
  chain
end
all_expectations_fulfilled?() click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 27
def all_expectations_fulfilled?
  all? {|method_name, chains| chains.all? {|chain| chain.expectation_fulfilled?}}
end
has_expectation?(method_name) click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 22
def has_expectation?(method_name)
  self[method_name].find {|chain| chain.is_a?(ExpectationChain)}
end
playback!(instance, method_name) click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 44
def playback!(instance, method_name)
  raise_if_second_instance_to_receive_message(instance)
  self[method_name].each {|chain| chain.playback!(instance)}
end
received_expected_message!(method_name) click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 39
def received_expected_message!(method_name)
  self[method_name].each {|chain| chain.expectation_fulfilled!}
end
remove_stub_chains_for!(method_name) click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 17
def remove_stub_chains_for!(method_name)
  self[method_name].reject! {|chain| chain.is_a?(StubChain)}
end
unfulfilled_expectations() click to toggle source

@private

# File lib/rspec/mocks/any_instance/message_chains.rb, line 32
def unfulfilled_expectations
  map do |method_name, chains|
    method_name.to_s if chains.last.is_a?(ExpectationChain) unless chains.last.expectation_fulfilled?
  end.compact
end

Private Instance Methods

raise_if_second_instance_to_receive_message(instance) click to toggle source
# File lib/rspec/mocks/any_instance/message_chains.rb, line 51
def raise_if_second_instance_to_receive_message(instance)
  @instance_with_expectation ||= instance if instance.is_a?(ExpectationChain)
  if instance.is_a?(ExpectationChain) && !@instance_with_expectation.equal?(instance)
    raise RSpec::Mocks::MockExpectationError, "Exactly one instance should have received the following message(s) but didn't: #{unfulfilled_expectations.sort.join(', ')}"
  end
end