13
我想測試一個方法調用鏈中的某個方法是否獲取特定參數。例如,在下面的代碼中,MyModel必須接收方法offset
的參數0。不幸的是下面的代碼不起作用。看起來不可能混用should_receive和stub_chain。我怎麼能解決這個問題?我使用的RSpec 2.stub_chain連同should_receive
MyModel.should_receive(:offset).with(0).stub_chain(:tag_counts, :offset, :limit, :order).and_return([]) # does not work!
的代碼我試圖測試:
tags = taggable.tag_counts.offset(page-1).limit(per_page).where(*where_clause).order("count DESC")
更新
我也貼在RSpec的谷歌集團的問題是大衛(RSpec的創造者)回答了它(感謝大衛):http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0?hl=en