现在我使用rrgem来存根项目模型计数方法,然后我复制索引操作来检查是否调用了计数方法。我计划使用mocha gem,但我不知道什么是mochagem中assert_received
方法的等价物。以下代码是我的测试示例之一。
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
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
希望这能有所帮助,这里是摩卡API。