如何断言Ruby on Rails测试中的输入元素是空的

时间:2011-06-10 14:58:55

标签: html ruby-on-rails forms testing

我想确保在编辑用户时密码字段为空。我如何在功能测试中做到这一点?

我尝试过这两种变体:

assert_select "input[name=?][value=?]", 'user[password1]', ''

assert_tag :tag => "input", :attributes => {:name => "user[password1]", :value => ""}

两者都失败,因为生成的html中没有value=属性。我没有看到任何测试生成的html中属性的方法吗?

2 个答案:

答案 0 :(得分:4)

试试这个:

assert_select 'input:not([value])[name="user[password1]"]', true

答案 1 :(得分:1)

黄瓜/网络上的

page.should_not have_xpath("//input[contains(@value, \"\")]")一样工作