rr gem assert_received 相当于 mocha gem
rr gem assert_received equivalent in mocha gem
现在我使用 rr gem 来存根项目模型计数方法,然后我复制索引操作来检查计数方法是否被调用。我打算使用 mocha gem,但我不知道 mocha gem 中 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
希望这对您有所帮助,这里是 mocha API。
现在我使用 rr gem 来存根项目模型计数方法,然后我复制索引操作来检查计数方法是否被调用。我打算使用 mocha gem,但我不知道 mocha gem 中 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
希望这对您有所帮助,这里是 mocha API。