如何在 Ruby on Rails 测试中断言输入元素为空

har*_*ald 3 html forms testing ruby-on-rails

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

我已经尝试了这两种变体:

assert_select "input[name=?][value=?]", 'user[password1]', ''
Run Code Online (Sandbox Code Playgroud)

assert_tag :tag => "input", :attributes => {:name => "user[password1]", :value => ""}
Run Code Online (Sandbox Code Playgroud)

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

Ale*_*xis 5

尝试这个:

assert_select 'input:not([value])[name="user[password1]"]', true
Run Code Online (Sandbox Code Playgroud)