如何在Ruby on Rails测试中声明输入元素为空 [英] How to assert that an input element is empty in Ruby on Rails tests
本文介绍了如何在Ruby on Rails测试中声明输入元素为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在编辑用户时确保密码字段为空。我如何在功能测试中做到这一点?
我已经尝试了这两种变体:
assert_select输入[name =?] [value =?],'user [password1]',''
和
assert_tag:tag => input,:attributes => {:name => user [password1],:value => }
因为没有 value =
属性存在于生成的html中。我看不到有什么方法可以测试生成的html中是否存在 不存在?解决方案
p>试试这个:
assert_select'input:not([value])[name =user [password1]]' ,真
I want to ensure that the password fields are empty when editing a user. How do I do this in a functional test?
I've tried both of these variants:
assert_select "input[name=?][value=?]", 'user[password1]', ''
and
assert_tag :tag => "input", :attributes => {:name => "user[password1]", :value => ""}
Both fail because there is no value=
attribute present in the generated html. I don't see any way of testing that an attribute is not present in the generated html?
解决方案
Try this:
assert_select 'input:not([value])[name="user[password1]"]', true
这篇关于如何在Ruby on Rails测试中声明输入元素为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文