rr gem assert_received equivalent in mocha gem

203 views Asked by At

Now I use rr gem to stub Project model count method, and then I replicate index action to check the count method is called or not. I'm planning to use mocha gem but I don't figure out what is the equivalent of assert_received method in mocha gem. Following code is one of the example of my tests.

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

There are 1 answers

0
ifyouseewendy On BEST ANSWER
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

Hope this can help, and here is the mocha API.