Why would RSpec report multiple validation errors of the same type?

二次信任 提交于 2019-12-13 05:43:12

问题


The following code:

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 

outputs: ["Title can't be blank", "Title can't be blank", "Title can't be blank"] and I can't figure out any specific reason this would happen but the way I experiencing things is that let and subject don't work very well lol

Even the following code produces the same errors:

  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

回答1:


The root of this issue was that some other spec was failing. When I got those specs passing this one did too. Very interesting.



来源:https://stackoverflow.com/questions/12254501/why-would-rspec-report-multiple-validation-errors-of-the-same-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!