【发布时间】:2011-09-29 13:19:45
【问题描述】:
我正在使用 testunit 2.4.0 为 rails 3.1 应用程序编写控制器测试。
我想断言某个标题没有出现在页面上。
我正在像这样使用 assert_select:
assert_select 'h1', {:text => /Key Dates/, :count => 0}
并得到以下错误:
ArgumentError: assertion message must be String or Proc: <</Key Dates/>
expected but was <"Planner Maternity leave">.>(<Test::Unit::Assertions::AssertionMessage>)
我发现这是因为assert_select 调用了build_message,它创建了一个AssertionMessage 的实例并将其传递给测试单元的assert。然而,在 testunit 2.2 版(2011 年 2 月)中,添加了检查传入消息类型的检查。这些检查会触发上面看到的 ArgumentError。
我不确定错误是否在于测试单元过于严格或 assert_select 传递了错误的对象类型。
您能建议如何最好地跟进这件事吗?有什么解决办法吗?
【问题讨论】:
-
:text中的值应该是字符串而不是模式的问题吗? -
嗨,不,将 :text 作为正则表达式是完全可以接受的
标签: ruby-on-rails ruby ruby-on-rails-3.1 testunit