我如何Flexmock链接ActiveRecord :: Relation?

时间:2011-11-02 18:27:48

标签: ruby-on-rails-3 activerecord rspec mocking

我想Flexmock是一个链接Rails 3 finder范围,

鉴于我有以下电话

  

User.where(:id => 1).first

和Flexmock代码

  

flexmock(User).should_receive(:where).with({:id =>   1})。and_return(用户)

但我得到一个错误,未知的方法'第一'用户。

1 个答案:

答案 0 :(得分:1)

您可以模拟where

where_mock = flexmock('Where', :first => user)
flexmock(User).should_receive(:where).with({:id => 1}).and_return(where_mock)