ここで、rr gem を使用して Project モデルの count メソッドをスタブ化し、index アクションをレプリケートして count メソッドが呼び出されたかどうかを確認します。mocha gem を使用する予定ですが、 mochaassert_received
gem のメソッドと同等のものは何かわかりません。次のコードは、私のテストの例の 1 つです。
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