作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我将以下代码放入 RSpec 测试中:
it { should validate_format_of(:email).not_with('test@test')}
并设置实际的类:
validates :email, :presence => true, :format => /\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i
当我运行测试时,我得到:
失败: 1)用户 失败/错误:它{应该 validate_format_of(:email).not_with('test@test')} 当电子邮件设置为“test@test”时,预期错误包括“can't be blank”,得到错误:[“name can't be blank (nil)”, “email is invalid (\"test@test\")"] # ./spec/models/user_spec.rb:8:in `block (2 levels) in '
当我通过以下测试时:
it { should validate_format_of(:email).with('adam@trimediatlantic.com')}
一切都按预期进行。有人可以告诉我我做错了什么还是框架问题。谢谢。
最佳答案
试试这个:
it { should_not allow_value("test@test").for(:email) }
关于ruby - 应该 validate_format_of 。 not_with 在框架中有问题(或者在我的理解中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4134432/
我将以下代码放入 RSpec 测试中: it { should validate_format_of(:email).not_with('test@test')} 并设置实际的类: validates
我是一名优秀的程序员,十分优秀!