Class: Object

Inherits:
BasicObject
Includes:
Grammar::Assert, Grammar::Expect, Grammar::Should
Defined in:
lib/quarry/mock.rb,
lib/quarry/stub.rb,
lib/quarry/grammar/assert.rb,
lib/quarry/grammar/expect.rb,
lib/quarry/grammar/should.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#mock(mock_module = nil) ⇒ Object

Create mock object.



63
64
65
66
67
68
69
70
71
# File 'lib/quarry/mock.rb', line 63

def mock(mock_module=nil)
  if mock_module
    Mock::Delegator.new(self, mock_module)
  else
    @_mock ||= Mock.new
    extend(@_mock)
    @_mock
  end
end

#remove_mock(mock_module = nil) ⇒ Object

We can’t remove the module per-say. So we have to just neuter it. This is a very weak solution, but it will suffice for the moment. – TODO: Use Carats for #unmix. ++



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/quarry/mock.rb', line 79

def remove_mock(mock_module=nil)
  mock_module ||= @_mock
  obj = self
  mod = Module.new
  mock_module.__table__.each do |interface, result|
    meth = interface[0]
    mod.module_eval do
      define_method(meth, &obj.class.instance_method(meth).bind(obj))
    end
  end    
  extend(mod)
end

#remove_stub(stub_module = nil) ⇒ Object

We can’t remove the module per-say. So we have to just neuter it. This is a very weak solution, but it will suffice for the moment. – TODO: Use Carats for #unmix. ++



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/quarry/stub.rb', line 77

def remove_stub(stub_module=nil)
  stub_module ||= @_stub
  obj = self
  mod = Module.new
  stub_module.__table__.each do |interface, result|
    meth = interface[0]
    mod.module_eval do
      define_method(meth, &obj.class.instance_method(meth).bind(obj))
    end
  end    
  extend(mod)
end

#stub(stub_module = nil) ⇒ Object

Create a new stub.



61
62
63
64
65
66
67
68
69
# File 'lib/quarry/stub.rb', line 61

def stub(stub_module=nil)
  if stub_module
    Stub::Delegator.new(self, stub_module)
  else
    @_stub ||= Stub.new
    extend(@_stub)
    @_stub
  end
end