ruby-on-rails – any_instance should_receive无法正常工作

我有这样的代码
@dns = "#{params[:domain].split('/').reverse.join('.')}.#{params[:zone]}"
w = Whois::Client.new
@r = w.query(@dns)

有路线:

match "domains/:zone/*domain" => "domains#show"

我正在使用Whois Gem

我想测试一下,所以我有一个测试:

it "should query 'google.com.ua' from /ua/com/google" do
    get :show,:zone => 'ua',:domain => 'com/google'
    dns = "google.com.ua"
    Whois::Client.any_instance.should_receive(:query).with(dns)
end

结果我得到:

Exactly one instance should have received the following message(s) but didn't: query

哪里可以问题?我100%肯定.query被调用

解决方法

调用查询方法后,您可能会设置期望值?

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...