How to mock class method in RSpec expect syntax?

匿名 (未验证) 提交于 2019-12-03 01:22:02

问题:

I have a confusion about how to mock a class method using new expect syntax. This works:

Facebook   .should_receive(:profile)   .with("token")   .and_return({"name" => "Hello", "id" => "14314141", "email" => "hello@me.com"}) 

and this doesn't:

facebook = double("Facebook") allow(facebook).to receive(:profile).with("token").and_return({"name" => "Hello", "id" => "14314141", "email" => "hello@me.com"}) 

Can someone tell me what is wrong here?

回答1:

Here's what you want to do (no need for double):

allow(Facebook)   .to receive(:profile)   .with("token")   .and_return({"name" => "Hello", "id" => "14314141", "email" => "hello@me.com"}) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!