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

name[RW]

Public Class Methods

new(name, stubs = {}) click to toggle source
# File lib/facon/mock.rb, line 20
def initialize(name, stubs = {})
  @name = name
  stub_out(stubs)
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
Calls superclass method
# 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

Private Instance Methods

stub_out(stubs) click to toggle source

Stubs out all the given stubs.

# File lib/facon/mock.rb, line 35
def stub_out(stubs)
  stubs.each_pair do |method, response|
    stub!(method).and_return(response)
  end
end