Class: RSpec::Mocks::AnyInstance::MessageChains

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

Instance Method Summary (collapse)

Constructor Details

- (MessageChains) initialize



6
7
8
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 6

def initialize
  @chains_by_method_name = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

- (Object) [](method_name)



11
12
13
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 11

def [](method_name)
  @chains_by_method_name[method_name]
end

- (Object) add(method_name, chain)



16
17
18
19
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 16

def add(method_name, chain)
  @chains_by_method_name[method_name] << chain
  chain
end

- (Boolean) all_expectations_fulfilled?



36
37
38
39
40
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 36

def all_expectations_fulfilled?
  @chains_by_method_name.all? do |method_name, chains|
    chains.all? { |chain| chain.expectation_fulfilled? }
  end
end

- (Boolean) has_expectation?(method_name)



29
30
31
32
33
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 29

def has_expectation?(method_name)
  @chains_by_method_name[method_name].find do |chain|
    ExpectationChain === chain
  end
end

- (Object) playback!(instance, method_name)



57
58
59
60
61
62
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 57

def playback!(instance, method_name)
  raise_if_second_instance_to_receive_message(instance)
  @chains_by_method_name[method_name].each do |chain|
    chain.playback!(instance)
  end
end

- (Object) received_expected_message!(method_name)



50
51
52
53
54
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 50

def received_expected_message!(method_name)
  @chains_by_method_name[method_name].each do |chain|
    chain.expectation_fulfilled!
  end
end

- (Object) remove_stub_chains_for!(method_name)



22
23
24
25
26
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 22

def remove_stub_chains_for!(method_name)
  @chains_by_method_name[method_name].reject! do |chain|
    StubChain === chain
  end
end

- (Object) unfulfilled_expectations



43
44
45
46
47
# File 'lib/rspec/mocks/any_instance/message_chains.rb', line 43

def unfulfilled_expectations
  @chains_by_method_name.map do |method_name, chains|
    method_name.to_s if ExpectationChain === chains.last unless chains.last.expectation_fulfilled?
  end.compact
end