2014-01-30 18 views
0

在rspec控制器規範中,如何在控制器中創建的對象上使用should_receive?如何在控制器中創建的對象上使用rspec should_receive?

我的理解是should_receive必須在調用動作之前被調用,並且在那一點上該對象不存在。這是如何完成的?

+0

同樣的問題http://stackoverflow.com/questions/21243833/how-to-stub-an-object-that-still-has-to-be-loaded-from-the-database-in -rspec – Danny

回答

0

一種方法是使用any_instance方法。

User.any_instance.should_receive(:name).and_return('John Doe') 
相關問題