[mocha-developer] Expect with "real world" returns?
Carl Mercier
carl at carlmercier.com
Wed May 21 22:29:18 EDT 2008
Here's a test file to illustrate what I'm saying.
#-------------
require File.dirname(__FILE__) + "/../test_helper"
class BlehTest < Test::Unit::TestCase
def foo(x)
"bar #{x}"
end
def test_foo
# fails, foo(1) returns nil
# ideally, this test should pass and execute the foo
# method since I didn't specify a return value
self.expects(:foo).with(1)
assert_equal "bar 1", foo(1)
end
def test_foo2
# fails, foo(1) returns nil, foo is already mocked,
# so totally understandable
self.expects(:foo).with(1).returns(foo(1))
assert_equal "bar 1", foo(1)
end
def test_foo3
# works, but verbose and not very dry. very tricky
# to do something like this in a real world scenario
output = foo(1)
self.expects(:foo).with(1).returns(output)
assert_equal "bar 1", foo(1) # success
end
end
#-------------
On 21-May-08, at 4:51 PM, Justin Reagor wrote:
>> So this is not really mocking, just setting expectations about what
>> will be called and with what arguments.
>
>
> Isn't that the current functionality though?
More information about the mocha-developer
mailing list