2016-09-15 16 views
1

私は(5)ビューヘルパーruby​​ on railsとassert_selectで無効なフィールドをテストするには?

form_for(@metric) do |f| 
    f.text_field :type, disabled: true 
end 

レールに発生した無効なフィールドの存在をテストしたいことはそれはおそらくちょうど

<input id="metric_type" type="text" name="metric[type]" value="Gamfora::Metric::Point" disabled> 

する必要がありますが、それはあるHTML

<input id="metric_type" type="text" name="metric[type]" value="Gamfora::Metric::Point" disabled="disabled"> 

を作成しますOKして仕事をしてください。


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 
です
関連する問題