我正在使用 gem fb_graph。我是 Rails 新手,正在尝试弄清楚如何使用 rspec 模拟这个 gem。(https://github.com/nov/fb_graph)
我试图测试的代码是:
facebook_user = FbGraph::User.new('me', :access_token => access_token['credentials']['token']).fetch
return facebook_user.friends
我在考虑以下几点:
fb_graph = mock(FbGraph)
user = mock(FbGraph::User)
fb_graph.should_receive(:new).should_return(user)
user.should_receive(:fetch).should_return(fb_graph_user)
user.should_receive(:friends)
谢谢!