本文介绍了如何在 RSpec 期望语法中模拟类方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对如何使用新的 expect
语法模拟类方法感到困惑.这有效:
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"})
这不会:
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?
推荐答案
这是你想要做的(不需要double
):
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"})
这篇关于如何在 RSpec 期望语法中模拟类方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!