Module: SimpleMock

Defined in:
lib/simple_mock.rb,
lib/simple_mock/tracer.rb,
lib/simple_mock/version.rb,
lib/simple_mock/mock_delegator.rb

Defined Under Namespace

Classes: MockDelegator, Tracer

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.new(object = nil) ⇒ Object

Returns a mock instance. For classicial mocking, call new without an argument.

mock = SimpleMock.new
mock.expect :meaning_of_life, 42
mock.meaning_of_life # => 42
mock.verify # => true

For hybrid mocking call new with an object argument. Hybrid mocking mixes expectations with real objects.

mock = SimpleMock.new Array.new
mock.expect :meaning_of_life, 42
mock.meaning_of_life # => 42
mock.push(1) # => [1]
mock.verify # => true

MiniTest::Mock and SimpleMock::MockDelegator have a 100% compatible API making no difference to the consumer.



30
31
32
33
34
35
36
# File 'lib/simple_mock.rb', line 30

def self.new object = nil
  if object.nil?
    MiniTest::Mock.new
  else
    MockDelegator.new object
  end
end