kommen (owner)

Forks

  • gist: 50008 by mig Mocha stub_path created Wed Jan 21 07:51:03 -0800 2009

Revisions

gist: 39288 Download_button fork
public
Public Clone URL: git://gist.github.com/39288.git
Embed All Files: show embed
mocha_stub_path.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Mocha
  module ObjectMethods
    def stub_path(path)
      path = path.split('.') if path.is_a? String
      raise "Invalid Argument" if path.empty?
      part = path.shift
      mock = Mocha::Mockery.instance.named_mock(part)
      exp = self.stubs(part)
      if path.length > 0
        exp.returns(mock)
        return mock.stub_path(path)
      else
        return exp
      end
    end
  end
end