Skip to content

Instantly share code, notes, and snippets.

@mig
Forked from kommen/mocha_stub_path.rb
Created January 21, 2009 15:51
Show Gist options
  • Select an option

  • Save mig/50008 to your computer and use it in GitHub Desktop.

Select an option

Save mig/50008 to your computer and use it in GitHub Desktop.

Revisions

  1. @kommen kommen created this gist Dec 23, 2008.
    17 changes: 17 additions & 0 deletions mocha_stub_path.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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