---
title: "Shoulda教程之三—测试ActiveRecord模型"
author: "chenk85"
date: "2008-05-11T05:28:37Z"
tags: []
slug: "shoulda-activerecord"
draft: false
lastmod: "2008-05-11T05:28:37Z"
id: 209280
url: "https://chenk85.iteye.com/blog/209280"
---

ActiveRecord助手方法 Shoulda具有一套ActiveRecord测试宏，这让开发效率大大提高，TDD变得轻而易举。关于这个方面的所有的文档都在Shoulda的Rdoc中。下面就来个小小的例子： class UserTest :dogs  should\_belong\_to :lover end 上面的代码创建了如下的测试： test: Person should allow phone\_number to be set to “(123) 456-7890″. test: Person should belong to lover. test: Person should have many dogs. test: Person should have many messes through dogs. test: Person should have one profile. test: Person should not allow admin to be changed by update. test: Person should not allow phone\_number to be set \[...]