我正在尝试对以下代码进行单元测试:
require 'mongoid'
class Seller
include Mongoid::Document
field :updated_at, type: Time
def update_updated_at
updated_at = Time.now
save
end
end
这是我的尝试
describe Seller do
describe 'update_updated_at' do
it 'sets updated_at to Time.now' do
now = Time.new(2013,10,14)
seller = Seller.new
mock(Time).now { now }
mock(seller).updated_at= now
mock(seller).save
seller.update_updated_at
end
end
end
我遇到以下失败
updated_at=(2013-10-14 00:00:00 -0600)
Called 0 times.
Expected 1 times.