any_instance should_receive无法正常工作

时间:2012-05-31 15:26:22

标签: ruby-on-rails ruby rspec rspec-rails

我有这样的代码:

@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被称为

1 个答案:

答案 0 :(得分:13)

看起来您可能在调用查询方法后设置了期望值吗?