0

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
Vega
  • 27,856
  • 27
  • 95
  • 103
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37

1 Answers1

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

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

ifyouseewendy
  • 6,674
  • 1
  • 21
  • 26