【发布时间】:2013-03-24 02:53:00
【问题描述】:
这个例子有点做作,但很好地解释了用例。
let( :number_of_users ){ User.count }
it 'counts users' do
User.create
number_of_users.should == 1
User.create
number_of_users.should == 2
end
此测试失败,因为 number_of_users 仅被评估一次,并且变得陈旧。有没有办法在每次调用时重新评估它?
【问题讨论】:
-
let()declerations 在第一次被调用时被评估。number_of_users应该是一个函数,因为这是您想要的行为。