Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assert that an input element is empty in Ruby on Rails tests

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?

like image 526
harald Avatar asked Dec 10 '25 20:12

harald


1 Answers

Try this:

assert_select 'input:not([value])[name="user[password1]"]', true
like image 100
Alexis Avatar answered Dec 12 '25 12:12

Alexis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!