如何在 Rspec 中规范 validates_uniqueness_of?
如何做到这一点?无法在线找到任何示例...(使用rspec 2.5.0
& rails 3.0.5
)
How does one do this? Couldn't find any examples online... (using rspec 2.5.0
& rails 3.0.5
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
shoulda-matchers
中找到它:http://rubydoc .info/github/thoughtbot/shoulda-matchers/master/framesFound it in
shoulda-matchers
: http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames不确定这是否正是您要查找的内容,但您可以在
保存
或更新
后检查错误消息,但老实说,这可能不是您需要测试的内容在你的单元测试中(如果这是你放置它们的地方)。您基本上是在重复 Rails 已经为您完成的单元测试。在 Cucumber 集成测试中检查视图中的错误消息会更合适。
Not sure if this exactly what you are looking for, but you could check the error messages after the
save
orupdate
But honestly, this is probably not something that you need to test in your unit tests (if that is where you are placing them). You are basically duplicating unit tests that Rails has already done for you. It would be more appropriate to check for the error message in the view in a cucumber integration test.