- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 testunit 2.4.0 为 Rails 3.1 应用编写 Controller 测试。
我想断言某个标题没有出现在页面上。
我像这样使用 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
的实例并将其传递给测试-单位的断言
。然而,在 testunit 的 2.2 版(2011 年 2 月)中添加了检查,用于检查传入的消息的类型。这些检查会触发上面看到的 ArgumentError
。
我不确定错误是在于测试单元过于严格还是 assert_select 传递了错误的对象类型。
您能建议如何最好地跟进吗?有什么变通办法吗?
最佳答案
因此,assert_select documentation显示以下示例,传入一个 block :
assert_select "ol" do |elements|
elements.each do |element|
assert_select element, "li", 4
end
end
那么如果你做了类似...的事情呢
assert_select 'h1' do |elements|
elements.length == 0 ? fail
elements.each do |element|
element.text ~= /Key Dates/ ? fail
end
end
如果找到模式或如果 h1
元素的数量为零,这基本上会失败。显然,您会更改条件以匹配您要测试的内容,但这是否让您更接近您的需要?
关于ruby-on-rails - 参数错误 : assertion message must be String or Proc using assert_select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7597931/
我想编写一个 View 测试来断言我的 HTML 中存在一个空数据属性。 我的 HTML 是这样的: 我的测试是: assert_select '[data-my-name-here]' 测试结果为
我在互联网上搜索了答案,但一无所获...这让我发疯! 没有assert_select 语句在我的任何测试中起作用。我已经反复确认该元素实际上位于目标页面的 dom 中——确实如此——但每个测试都在 a
可否assert_select工作后 assert_redirected_to ?我有以下 Controller 操作,但失败了。 test "get switchboard" do ...
我的 html 代码中有这个字符串: 1\n \n word 我想创建一个忽略那些新行和空格的 assert_select,所以我试过这个: assert_se
有谁知道如何让 assert_select 在 rake 测试期间不输出所有那些讨厌的 html 警告?你知道,像这样的东西: .ignoring attempt to close body with
给定 View 中的 HTML: Recover Pasword 如何使用 assert_select 选择按钮的值?我试
我的页面应该包含一个类似于 Click to go 的链接. 您将如何使用 assert_select 对此进行测试?我想检查是否存在 a用 href="/desired_path/1" 标记.如何测
我正在努力测试我的选择框的值是否为 6。 1 我的 rspec 代码 assert_select "select#line_item_quantity", value: 6 无论
有如下所示的 XML,我如何assert_select 标记 atom:link? Title http://example.com Description
我的代码是 This is Jhon's account 测试此代码的行是 assert_select "h3#account_owner", "This is Jhon's account" 测试失
在 Rails 3.2.8 Controller 测试中,我想使用 assert_select使用 raw 控制在我的 View 中呈现的未转义字段的内容或 #html_safe方法:
我正在编写一个简单的测试来检查表单是否加载了正确的值。 我浏览了文档,似乎找不到一个示例来说明如何验证表单输入的值。 我有一个呈现用户名的表单。 我只想用 assert_select在文本输入上并验证
我正在我的 Rails 应用程序中尝试以下测试: test "markup need for store.js.coffee is in place" do get :index assert
我有以下 html 表: Name Permission test user01 Reading permis
据我了解,assert_select是一种用于测试 HTML 状态的 Capybara 方法 元素,和 assert_selector用于测试任何 HTML 元素及其内部文本的存在。 那么,为什么会:
我有一个默认为空白的 span 元素,并在通过 javascript 加载页面时更新。这很有效 - 然而,assert_select 似乎只能在页面加载完成之前获取初始 HTML。这是预期的行为吗?我
我刚开始使用 Rails 并测试我的 Plants 的索引页型号: rspec 测试失败并显示此消息: $ rspec spec/views/plants/index.html.haml_spec.r
我是测试新手,所以如果我的方法有问题,请随时纠正我。 我正在使用 Minitest 测试 Rails4 应用程序。由于我在许多页面中包含 JS,因此我使用 Capybara 在我的测试中使用 JS 驱
我正在做 Rails 集成测试,有人写了当时通过的测试,但现在他们发出警告 这是我正在处理的代码行 assert_select "a[href=/monster_xml_users/#{user_xm
我有一个 Rails View ,它输出的 HTML 类似于: Keywords EN Accepted Foo Rejecte
我是一名优秀的程序员,十分优秀!