Class: RSpec::Mocks::AnyInstance::Recorder

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

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Recorder

Returns a new instance of Recorder.



104
105
106
107
108
109
110
# File 'lib/rspec/mocks/any_instance.rb', line 104

def initialize(klass)
  @message_chains = {}
  @observed_methods = []
  @played_methods = {}
  @klass = klass
  @expectation_set = false
end

Instance Method Details

#instance_that_received(method_name) ⇒ Object



136
137
138
# File 'lib/rspec/mocks/any_instance.rb', line 136

def instance_that_received(method_name)
  @played_methods[method_name]
end

#playback!(instance, method_name) ⇒ Object



129
130
131
132
133
134
# File 'lib/rspec/mocks/any_instance.rb', line 129

def playback!(instance, method_name)
  RSpec::Mocks::space.add(instance)
  @message_chains[method_name].playback!(instance)
  @played_methods[method_name] = instance
  received_expected_message!(method_name) if has_expectation?(method_name)
end

#should_receive(method_name, *args, &block) ⇒ Object



117
118
119
120
121
# File 'lib/rspec/mocks/any_instance.rb', line 117

def should_receive(method_name, *args, &block)
  observe!(method_name)
  @expectation_set = true
  @message_chains[method_name] = ExpectationChain.new(method_name, *args, &block)
end

#stop_all_observation!Object



123
124
125
126
127
# File 'lib/rspec/mocks/any_instance.rb', line 123

def stop_all_observation!
  @observed_methods.each do |method_name|
    restore_method!(method_name)
  end
end

#stub(method_name, *args, &block) ⇒ Object



112
113
114
115
# File 'lib/rspec/mocks/any_instance.rb', line 112

def stub(method_name, *args, &block)
  observe!(method_name)
  @message_chains[method_name] = StubChain.new(method_name, *args, &block)
end

#verifyObject



140
141
142
143
144
# File 'lib/rspec/mocks/any_instance.rb', line 140

def verify
  if @expectation_set && !each_expectation_filfilled?
    raise RSpec::Mocks::MockExpectationError, "Exactly one instance should have received the following message(s) but didn't: #{unfulfilled_expectations.sort.join(', ')}"
  end
end