我想测试在 rails(5) View 助手中生成的禁用字段是否存在
form_for(@metric) do |f|
f.text_field :type, disabled: true
end
它创建 HTML
<input id="metric_type" type="text" name="metric[type]" value="Gamfora::Metric::Point" disabled="disabled">
应该只是
<input id="metric_type" type="text" name="metric[type]" value="Gamfora::Metric::Point" disabled>
但没关系,完成工作。
在 Firebug 中,我验证 CSS 选择器是 input#metric_type:disabled
。
但是当我在 Controller (+ View )测试中使用它时
assert_select "input#metric_type:disabled"
我得到错误
RuntimeError: xmlXPathCompOpEval: function disabled not found
有什么办法,如何测试通过ID选择的输入被禁用?
最佳答案
一个解决方案是
assert_select ".field input#metric_type" do |input|
assert input.attr("disabled").present?
end
关于ruby-on-rails - 如何测试 ruby on rails 和 assert_select 中的禁用字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39512040/