【发布时间】:2010-03-11 15:33:39
【问题描述】:
我目前正在尝试为通过 AJAX(jQuery) 加载到页面上的收费表单编写功能测试。它从charge_form 动作加载表单,该动作返回consult_form.js.erb 视图。
这一切正常,但我的测试有问题。
在函数中,我可以执行操作,但我不能使用 assert_select 来查找元素并验证表单是否确实存在。
错误:
1) Failure:
test_should_create_new_consult(ConsultsControllerTest) [/test/functional/consults_controller_test.rb:8]:
Expected at least 1 element matching "h4", found 0.
<false> is not true.
这是视图。 Consult_form.js.erb:
<div id="charging_form">
<h4>Charging form</h4>
<div class="left" id="charge_selection">
<%= select_tag("select_category", options_from_collection_for_select(@categories, :id, :name)) %><br/>
...
consults_controller_test.rb:
require 'test_helper'
class ConsultsControllerTest < ActionController::TestCase
def test_should_create_new_consult
get_with_user :charge_form, :animal_id => animals(:one), :id => consults(:one), :format => 'js'
assert_response :success
assert_select 'h4', "Charging form" #can't find h4
end
end
使用非html类型的assert_select有问题吗?
感谢您的帮助!
【问题讨论】:
标签: javascript ruby-on-rails functional-testing