Test for missing input tag value attribute

How can I confirm the absence of an HTML attribute in a Rails RSpec test?

I can verify that the tag inputhas an attribute valueand that it is an empty string:

response.should have_tag("input[name=?][value=?]", "user[password]", "")
response.should have_tag("input[name=?][value=?]", "user[password_confirmation]", "")

But I want to check that my input fields do not have an attribute at all value(i.e. an empty field).

+3
source share
3 answers

It revealed:

response.should_not have_tag("input[name=?][value]", "user[password]")
response.should_not have_tag("input[name=?][value]", "user[password_confirmation]")

Just use the attribute valuewithout =? part. Therefore, if the tag inputhas an attribute value, regardless of what it contains, the test will fail.

+3
source

, , has_tag , , has_tag.

- has_selector:

    response.should have_selector("input#user_password", :content => "")

user_password - id ( ), , ( ), , id .

, , : content "x", .

rspec-rails 2.5.0 rspec 2.5.0

+1

What about response.should_not have_tag("....")

0
source

Source: https://habr.com/ru/post/1750532/


All Articles