问题
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