【问题标题】:How to test disabled field in ruby on rails and assert_select?如何测试 ruby​​ on rails 和 assert_select 中的禁用字段?
【发布时间】:2016-09-15 13:16:35
【问题描述】:

我想测试 rails(5) 视图助手中生成的禁用字段的存在

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

但是当我在控制器(+视图)测试中使用它时

assert_select "input#metric_type:disabled"

我得到错误

RuntimeError: xmlXPathCompOpEval: function disabled not found

有什么办法,如何测试ID选择的输入被禁用?

【问题讨论】:

    标签: ruby-on-rails ruby css-selectors integration-testing


    【解决方案1】:

    一个解决方案是

    assert_select ".field input#metric_type" do |input|
        assert input.attr("disabled").present?
    end 
    

    【讨论】:

      猜你喜欢
      • 2017-04-14
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多