我想测试一个特定的图标是否会显示在一个用户的视图中,该用户的连续性超过 X 天。所以我需要存根模型的一个streak
方法。但User
我希望它只为基于它的特定用户存根方法uid
。测试代码如下。
test "should display an icon for users with streak longer than 7 days" do
node = node(:one)
User.any_instance.stubs(:streak).returns([8,10])
get :show,
author: node.author.username,
date: node.created_at.strftime("%m-%d-%Y"),
id: node.title.parameterize
assert_select ".fa-fire", 1
end
返回值是一个数组,数组中的第一个值是连续的天数,第二个值是该连续的帖子数。
该行User.any_instance.stubs(:streak).returns([8,10])
存根类的任何实例User
。我怎样才能存根它以便它只存根那些实例:uid => 1
?