为什么 RSpec 会报告多个相同类型的验证错误? [英] Why would RSpec report multiple validation errors of the same type?

查看:49
本文介绍了为什么 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 

outputs: ["Title can't be blank", "Title can't be blank", "Title can't be blank"] 我想不出任何具体的原因这会发生,但我经历事情的方式是 let 和 subject 不能很好地工作,哈哈

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

推荐答案

这个问题的根源是其他一些规范失败了.当我通过这些规格时,这个规格也通过了.很有趣.

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

这篇关于为什么 RSpec 会报告多个相同类型的验证错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆