现在我使用rr gem 来存根项目模型的计数方法,然后我复制索引操作来检查计数方法是否被调用。我打算使用 mocha gem,但我不知道mochaassert_received
gem 中方法的等价物是什么。以下代码是我的测试示例之一。
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