2015-06-23 48 views
0

現在我用rr gem來存根項目模型計數方法,然後我複製索引動作來檢查計數方法是否被調用。我打算使用摩卡寶石,但我不知道什麼是assert_received方法摩卡寶石的等值。以下代碼是我測試的例子之一。rm gem assert_remived當前在摩卡寶石

require 'test_helper' 

class ProjectsControllerTest < ActionController::TestCase 
    context "on GET to index" do 
    setup do 
     stub(Project).count { 30000 } 
     get :index 
    end 

    should "load up the number of gems, users, and downloads" do 
     assert_received(Project)  { |subject| subject.count } 
    end 
    end 
end 

回答

1
require 'test_helper' 

class ProjectsControllerTest < ActionController::TestCase 
    context "on GET to index" do 
    setup do 
     Project.stubs(:count).returns(30000) 
    end 

    should "load up the number of gems, users, and downloads" do 
     Project.expects(:count).returns(30000) 
     get :index 
    end 
    end 
end 

希望這可以幫助,這裏是mocha API。