gpt4 book ai didi

ruby-on-rails - rr gem assert_received 相当于 mocha gem

转载 作者:行者123 更新时间:2023-11-28 21:28:50 25 4
gpt4 key购买 nike

现在我使用 rr gem 来 stub 项目模型的计数方法,然后我复制索引操作来检查计数方法是否被调用。我打算使用 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。

关于ruby-on-rails - rr gem assert_received 相当于 mocha gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31006721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com