Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created December 11, 2009 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjb3/254456 to your computer and use it in GitHub Desktop.
Save pjb3/254456 to your computer and use it in GitHub Desktop.
require 'test/unit'
require 'rubygems'
require 'mocha'
class Class1
def foo
c2 = Class2.new
x = c2.bar
c2.baz(x)
end
end
class Class2
def bar
21
end
def baz(x)
x * 2
end
end
class MyTest < Test::Unit::TestCase
def test_foo
n = 99
c2 = mock()
Class2.expects(:new).returns(c2)
c2.expects(:bar).returns(n)
c2.expects(:baz).with(n).returns(1)
assert_equal 1, Class1.new.foo
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment