0
下面的代碼:爲什麼RSpec會報告同一類型的多個驗證錯誤?
describe Task do
let(:task) { Task.new }
subject { task }
before(:each) do
task.valid?
p task.errors.full_messages
end
it { should have(1).error_on(:title) }
it { should have(1).error_on(:description) }
end
輸出:["Title can't be blank", "Title can't be blank", "Title can't be blank"]
,我想不出任何具體原因會發生這種情況,但我遇到事情的方式是,讓並受不工作得很好笑
即使下面的代碼產生相同的錯誤:
it "should have 1 error on title" do
Task.new.should have(1).error_on(:title)
end
it "should have 1 error on description" do
Task.new.should have(1).error_on(:description)
end