I need to make fun of the following:
Class User
def facebook
end
end
So, in my user tests, in order to access facebook user information, I need to call user.facebook.me.infoto get the information. If I want to mock this, I am currently using the following:
@user = Factory(:user)
facebook = mock()
me = mock()
me.expects(:info).returns({"name" => "John Doe"})
facebook.expects(:me).returns(me)
@user.expects(:facebook).returns(facebook)
assert_equal "John Doe", @user.facebook.me.info["name"]
This works, but it seems a little cumbersome, is there a better way to do this?
[edit] I use mocha as a mockery of the framework
source
share