2016-09-15 26 views
1

我想測試中軌(5)視圖助手產生的無效字段的存在如何測試Ruby on Rails和assert_select中的禁用字段?

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選擇被禁用?

回答

1

一種解決方案是

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