我有一些問題,指出我的模型,它充當狀態機(gem state_machine 0.9.4)的驗證。通過stat_machine,我定義爲自行車的狀態發表了驗證:rspec:錯誤的屬性(存在)沒有找到
state :delivered do
validates_presence_of :shipping_number
end
在我的規格
這個作品的權利:
it "may not transit to :delivered without a shipping number " do
@bike.state = 'delivered'
@bike.shipping_number = nil
@bike.save
@bike.should have(1).error_on(:shipping_number)
end
但間距標準像這樣的時候:
it "may not transit to :delivered without a shipping number " do
@bike.shipping_number = nil
@bike.deliver
@bike.should have(1).error_on(:shipping_number)
end
我獲得:
expected 1 error on :shipping_number, got 0
即使
it "may not transit to :delivered without a shipping number " do
@bike.shipping_number = nil
@bike.deliver
raise @bike.errors.inspect
end
顯示我:
Failure/Error: raise @bike.errors.inspect
#<OrderedHash {:shipping_number=>["can't be blank"]}>
有人能解釋一下嗎?
我有同樣的問題,是你能解決嗎? – nktokyo 2011-01-27 14:12:02