Rails 测试:设置、执行与数据处理
1. 常用断言方法
在 Ruby 的测试中,有一些常用的断言方法:
- assert_respond_to(object, method) :当 object.respond_to?(method) 为 true 时,测试通过。
- assert_send(array) :这是一个比较奇特的方法,它接受一个格式为 [receiver, method, argument_list] 的数组,若 receiver.method(argument_list) 为 true ,则测试通过。
- assert_throws(symbol, &block) 和 assert_nothing_thrown(&block) :与 assert_raise 类似,但针对的是 Ruby 中较少使用的 catch/throw 机制。
2. 测试的设置与拆解
在编写测试时,我们可能会遇到多个测试用例存在重复设置代码的情况。例如:
test "a user should be able to see an update within the project" do
fred = User.new(:name =&
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



