class Facon::Mock
A mock object is a ‘fake’ object on which you can impose simulated behavior. Defining expectations and stubs on mock objects allows you to specify object collaboration without needing to actually instantiate those collaborative objects.
Examples¶ ↑
mock = mock('A name') mock = mock('Mock person', :name => 'Konata', :sex => 'female')
Attributes
Public Class Methods
Source
# File lib/facon/mock.rb, line 20 def initialize(name, stubs = {}) @name = name stub_out(stubs) end
Public Instance Methods
Source
# File lib/facon/mock.rb, line 25 def method_missing(method, *args, &block) super(method, *args, &block) rescue NameError # An unexpected method was called on this mock. mock_proxy.raise_unexpected_message_error(method, *args) end
Calls superclass method
Private Instance Methods
Source
# File lib/facon/mock.rb, line 35 def stub_out(stubs) stubs.each_pair do |method, response| stub!(method).and_return(response) end end
Stubs out all the given stubs.